Monday, 12 August 2013

How can I flatten results from left join using MySQL?

How can I flatten results from left join using MySQL?

I'm trying to create a query where I join a USER table with an
ADDRESS_BOOK table in which 1 user may have multiple addresses (i.e.
billing, shipping). Each address is its own entry in the ADDRESS_BOOK
table.
Each entry in the ADDRESS_BOOK table has a USER_ID value that corresponds
to one entry in the USER table.
I would like to get the following results:



USER ID | BILLING | SHIPPING
Right now I get two results per USER_ID, one for the SHIPPING address, and
one for the BILIING address. I need to get one result per USER_ID where
the SHIPPING and the BILLING information (the two query results) are
flattened.
Thanks!

No comments:

Post a Comment