Going crazy trying to set a variable in a query of type:
SET @idcamposexcluidos='817,803,495';
so i can then use it on a
WHERE id_campo not in (@idcamposexcluidos)
I've tried defining the variable in different formats with no luck and don't seem to find an specific example for the above:
SET @idcamposexcluidos='(817,803,495)';
...
WHERE id_campo not in @idcamposexcluidos
SET @idcamposexcluidos=817,803,495;
with no success. It either returns an error or ignores the values.
in
like that. You need seperate variables or use a dynamic SQL. – juergen d Aug 14 '12 at 17:33FIND_IN_SET
andLIKE
are OK for small tables. But they do not perform well because they have to look at every row. Most languages have no simple way (if any way) to construct the much fasterIN(...)
clause, which can use an index. – Rick James Jul 12 '19 at 6:12