homepage Welcome to WebmasterWorld Guest from 54.146.175.204
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Can I union these
Mysql query
roslan



 
Msg#: 4173958 posted 11:58 am on Jul 21, 2010 (gmt 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

 

syber

10+ Year Member



 
Msg#: 4173958 posted 10:19 pm on Jul 21, 2010 (gmt 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.

roslan



 
Msg#: 4173958 posted 12:11 am on Jul 22, 2010 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved