what what - 3 months ago 13
SQL Question

SELECT * WHERE var == [one of many alternatives]

In MySQL, I can specify an alternative match with

OR
:

SELECT * FROM table WHERE var = 1 OR var = 2


When there are many alternatives, listing them all like this will become cumbersome. Is there a way, where I can give a list, vector or array of values? Sort of like this pseudocode:

SELECT * FROM table WHERE var IN {1, 2, 5, 11, 45}

Answer

You can specify IN with parenthesis rather than braces.

SELECT * FROM table WHERE var IN (1, 2, 5, 11, 45)
Comments