i store lists of ids inside fields (by list i mean val1,val2,val3,...), and i want to select rows from a table where the field has valX in the list.
i thought this would work, but apparently not 🙁
SELECT *
FROM userbulletins
WHERE 25 IN `currentMessages`
OR 25 IN `removedMessages`
OR 25 IN `readMessages`
currentMessages, removedMessages, and readMessages are fields with ids stored as lists
i’ve also tried
SELECT *
FROM userbulletins
WHERE "25" IN(`currentMessages`)
both return nothing (and should return 1 row in my test db)
any idea what i’m doing wrong? or if this is even possible?
thanks!
If I understand correctly, you have a denormalized table where the
currentMessagesvalue can be “val1,val2,val3,…” and you want to find rows where 25 is one of those values? If so, use the FIND_IN_SET function:…but I really recommend normalizing your data to make querying easier.