dtyson2000 Posted February 10, 2007 Share Posted February 10, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/37891-use-join-or-something-else/ Share on other sites More sharing options...
effigy Posted February 10, 2007 Share Posted February 10, 2007 See this topic. Quote Link to comment https://forums.phpfreaks.com/topic/37891-use-join-or-something-else/#findComment-181420 Share on other sites More sharing options...
worldworld Posted February 10, 2007 Share Posted February 10, 2007 Use GROUP BY in sql statement as a solution... Quote Link to comment https://forums.phpfreaks.com/topic/37891-use-join-or-something-else/#findComment-181490 Share on other sites More sharing options...
fenway Posted February 11, 2007 Share Posted February 11, 2007 Yup, GROUP_CONCAT() is the way to go, if you must do it in SQL. Quote Link to comment https://forums.phpfreaks.com/topic/37891-use-join-or-something-else/#findComment-182271 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.