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)

5+ Year Member

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 Jul 21, 2010 (gmt 0)

10+ Year Member

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 Jul 22, 2010 (gmt 0)

5+ Year Member

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month