I've noticed something odd about user-defined variables:
Lets say I have this table:
num_table
+---------+
| numbers |
| 3 |
| 6 |
| 9 |
+---------+
I can create a comma-separated list and store it in a user-defined variable like so:
SELECT @var := GROUP_CONCAT `numbers` from num_table;
Which will assign the value 3,6,9
to @var
.
And here is the odd part. Running
SELECT 3 IN (@var)
returns 1, but running
SELECT 6 IN (@var)
returns 0.
It seems to me it should either work or not work. Any idea why it works only with the first number in the list?