Select from array in MySQL

I think you mean something like this?

SELECT 1 UNION SELECT 2 UNION SELECT 3

The only way to create a virtual set in MySQL is using a subquery with UNION. The subquery in the FROM clause creates 3 rows which can be joined with another table:

SELECT foo.*
FROM (
    SELECT 1 AS num UNION
    SELECT 2 AS num UNION
    SELECT 3 AS num
) virtual
LEFT JOIN foo ON foo.num = virtual.num

When you want to use your list of values as a condition for WHERE or ON clause, then the IN() construct may be the right way to go:

SELECT foo.* FROM foo WHERE foo.num IN (1,2,3)

sorry for my english

you can use (IN) like this

SELECT * FROM Table WHERE id IN (1,2,3....) 

Tags:

Mysql