I need to check if one (or more) of several values is present in a SQL array. In its simplest form it would look something like this:
SELECT
(1, 7, 8) IN (1, 2, 3, 4, 5)
FROM DUAL
Obviously this statement won't work. It only works if I check for just one value in the array. But I need to know if one (not all!) of the values I supply is present in the SQL array. The statement should return TRUE if one or more values are present in the array and FALSE if none is.
I realize I could just add several checks, like this:
SELECT
1 IN (1, 2, 3, 4, 5)
OR 7 IN (1, 2, 3, 4, 5)
OR 8 IN (1, 2, 3, 4, 5)
FROM DUAL
My programming logic however supplies the values in array format "(1, 7, 8)" and the amount of values in this array differs every time i need to run the SQL statement. It would be very handy if I could somehow just paste this array into my existing SQL statement instead of rebuilding the SQL statement on every run, and create the "OR" statements for every value in the array.
Is there a way to do this? I'm using MySQL btw.
Thanx in advance, keep up the good programming!
datatableor an array. A comma-separated list is not an array, its a string.