Reputation: 2110
I now gave up and sorted it by other means but because "curiosity killed the cat" I am trying to figure out how to use mysql query @variables within an IN where statement:
So, from this:
SELECT * FROM table1 WHERE table1.ID IN (794,758)
Try to include a variable and this returns a syntax error:
SET @variousids="(794,758)";
SELECT * FROM table1 WHERE table1.ID IN @variousids
This returns values only from the first:
SET @variousids="794,758";
SELECT * FROM table1 WHERE table1.ID IN (@variousids)
I've tried different syntax, values and have not found any specific doc about defining list of values.
Upvotes: 4
Views: 3555
Reputation: 8639
Try :-
SET @variousids="794,758";
SELECT * FROM table1 WHERE table1.ID FIND_IN_SET (table1.ID,@variousids)
Upvotes: 1
Reputation:
Use find_in_set
. The below will work.
SET @variousids="794,758";
SELECT * FROM table1 WHERE find_in_set(table1.ID,@variousids)
Upvotes: 8