Reputation: 4105
I'm trying to get all rows from my table by their id (the IDs are auto incremented) by searching for the IDs.
I'm trying something like this:
SELECT *
FROM table
WHERE something = 'yes' AND (csvstring)
Where csvstring is something like this: 4, 53, 34, 23
The problem is that I don't think that you can do that. I tried "WHERE id IN (csvstring)" because I was googling this but that didn't work
any help would be greatly appreciated!
Upvotes: 0
Views: 104
Reputation: 263713
The reason for that in id IN (csvstring)
is because the query parses csvstring
as a whole string and not as a particular id. You want to have like this: id IN (4, 53, 34, 23)
but the query sees it like this id IN ('4, 53, 34, 23')
Maybe FIND_IN_SET works for you.
Try some thing this,
SELECT... FROM... WHERE something='yes' AND id IN (4,53,34,23)
Upvotes: 0
Reputation: 2080
SELECT *
FROM table
WHERE something='yes' AND id IN (4,53,34,23)
That doesn't work? Edit: Just tested it, it does work.
Upvotes: 1