Here's the situation: I'm running a query (in MySQL) against a non-normalized table. I didn't build it, don't blame me. One column in this table consists of a comma delimited list of image_ids.
These image IDs correspond to the Primary Key
within a second table.
I'm trying to do a LEFT JOIN
in my SQL
, in order to get the images attached to the content:
LEFT JOIN image ON image.id IN (content.imageIDs)
This errors as content.imageIDs are not wrapped in quotes, instead it's just 12345,67890, etc.
If I can wrap these individual IDs in quotes, it should work. However, I can't work out how to do that.
LEFT JOIN image ON image.id IN (REPLACE(content.imageIDs, ',', '\',\''))
This gets me closer, but now I'm missing the opening and closing quotes. I've tried using CONCAT()
to add these, which results in no error, but no results either.