
Originally Posted by
EasyCo
Can you re-explain what you're suggesting, I don't entirely understand in regards to extracting all locations....
Cheers!
I wrote 'with GROUP_CONCAT' when I wanted to write 'without GROUP_CONCAT'. 
Code:
SELECT products.id
, products.title
, product_locations.title as product_location
, products.cost
, products.extra_cost
, products.extra_cost_note
, products.saving_note
, products.picture_url
, COALESCE(l.location,"") AS locations
, COALESCE(e.extras,"") AS extras
, products.status
FROM products
LEFT OUTER JOIN
( SELECT product_pickup.product_id
, pickup_locations.location
FROM product_pickup
INNER JOIN pickup_locations
ON pickup_locations.id = product_pickup.pickup_id
) AS l
ON l.product_id = products.id
LEFT OUTER JOIN
( SELECT product_extras.product_id
, GROUP_CONCAT(extras.title SEPARATOR "\n") AS extras
FROM product_extras
INNER JOIN extras
ON extras.id = product_extras.extras_id
GROUP BY product_extras.product_id ) AS e
ON e.product_id = products.id
LEFT OUTER JOIN
product_locations on products.product_location = product_locations.id
WHERE products.status IN ( 1 , 2 )';
As you can see I eliminated the GROUP_CONCAT from the first subquery. It means that if a product has two pickup locations, now it will have two rows in the query result. All columns of those two rows will have the same values (product id, title, ecc) except for the locations column. So to display the product info like you did before, you'll have to handle this new situation (more than 1 row for 1 product).
Bookmarks