Welcome Guest, Not a member yet? Register   Sign In
JOIN problem
#2

[eluser]danmontgomery[/eluser]
There isn't a way to do what you're describing, since that would require a result set with two identically named columns. What you probably want is GROUP_CONCAT, which will return all of the product_id's as a string in one field, you can specify a separator and explode them out that way. You'll also need to GROUP the results to get what you want.

SELECT `orders`.`id`, `orders`.`order_date`, `orders_items`.`order_id`, GROUP_CONCAT( DISTINCT `orders_items`.`product_id` SEPARATOR '|' ) AS product_ids
FROM (`orders`)
JOIN `orders_items` ON `orders_items`.`order_id` = `orders`.`id`
WHERE `orders`.`customer_id` = '19'
GROUP BY `orders`.`id`

Should work for you, returning the multiple product id's as the string "1|3". (The 'DISTINCT' is probably optional, it will only give you distinct values in the case that there are 2 records for an order with the same product id).


Messages In This Thread
JOIN problem - by El Forum - 01-07-2010, 03:12 PM
JOIN problem - by El Forum - 01-07-2010, 03:55 PM
JOIN problem - by El Forum - 01-07-2010, 04:00 PM
JOIN problem - by El Forum - 01-07-2010, 04:03 PM
JOIN problem - by El Forum - 01-07-2010, 04:07 PM
JOIN problem - by El Forum - 01-07-2010, 08:22 PM
JOIN problem - by El Forum - 01-07-2010, 09:29 PM
JOIN problem - by El Forum - 01-07-2010, 10:39 PM
JOIN problem - by El Forum - 01-08-2010, 07:52 AM
JOIN problem - by El Forum - 01-09-2010, 12:18 AM
JOIN problem - by El Forum - 01-09-2010, 01:55 PM
JOIN problem - by El Forum - 01-09-2010, 02:18 PM
JOIN problem - by El Forum - 01-10-2010, 10:34 AM
JOIN problem - by El Forum - 01-10-2010, 10:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB