Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Can I union these

Mysql query

11:58 am on Jul 21, 2010 (gmt 0)

New User

5+ Year Member

joined:July 21, 2010
posts: 2
votes: 0

I have these tables:

client(idclient, name, reference)
address(idaddress, idclient)
inv(idinvoice, idaddress, total, datetime)
payment(idpayment, idinvoice, amount, pdatetime)

INTO something like

client reference time idinvoice idpayment amount
xyz a2345 2010-03-01 2342 NULL -(amount)
xyz a2345 2010-02-12 2341 NULL -(amount)
xyz a2345 2010-03011 NULL 2222 amount

inv.total as amount, datetime and pdatetime as time, where idaddress = 9
10:19 pm on July 21, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 12, 2004
votes: 0

No, a UNION statement is used to append similar rows from multiple tables. To get the output you want you would need to do a JOIN, however, I don't see the idclient column in the inv or payment tables.
12:11 am on July 22, 2010 (gmt 0)

New User

5+ Year Member

joined:July 21, 2010
votes: 0

inv connected to address to client,
payment connected to inv

My output will be

client reference idinvoice idpayment amount

I inserted some sample data above, but on posting, it strays into another column. The sequence is right though.

inv.total is to be in the same column as payment.amount AS amount negative.

datetime and pdatetime under same column as time.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members