Jump to content

Use JOIN or something else?


dtyson2000

Recommended Posts

Hello...

 

The following query:

SELECT customers.*, orders.*, orders_products.* FROM customers, orders, orders_products WHERE (customers.customers_id = orders.customers_id) && (orders.orders_id = orders_products.orders_id);

returns orders placed by customers which are entered into the database as separate rows for each product ordered. So If Customer 1 orders a dog, a cat and a bird, it returns three rows saying such (each with the same customer info, same order id but different product):

 

customers_id | orders_id | orders_products

1 | 1 | dog

1 | 1 | cat

1 | 1 | bird

 

I would like to return this information in one row saying:

 

customers_id | orders_id | orders_products

1 | 1 | dog, cat, bird

 

As it is, when I use GROUP BY either customers_id or orders_id, I get only the last row in the set (i.e. 1 | 1 | bird).

 

I've tried various JOINS but am not sure how this is to be done.

 

Anybody able to help out?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.