I have two tables.
products
id title image_ids
---------------------
1 myproduct 1,2,3
images
id title file_name
-------------------------
1 myimage myimage.jpg
2 myimage2 myimage2.jpg
3 myimage3 myimage3.jpg
I want to query so that the names of the images are concatenated into a single field for each product reference.
This query doesn't work
SELECT products.title,
products.image_ids,
GROUP_CONCAT(images.file_name)
FROM products
LEFT JOIN images ON images.id IN (products.image_ids)
WHERE products.id = 1
GROUP BY products.id
This one does:
SELECT products.title,
products.image_ids,
GROUP_CONCAT(images.file_name)
FROM products
LEFT JOIN images ON images.id IN (1,2,3)
WHERE products.id = 1
GROUP BY products.id
And produces the desired results
title image_ids file_names
--------------------------------------------------------------
myproduct 1,2,3 myimage.jpg,myimage2.jpg,myimage3.jpg
Why doesn't the first query work when it is asking the same thing as the second query and how can I make it work.