[Solved] mysql user defined variables as derived table


Are you looking for something like this?

SELECT *
  FROM
(
  SELECT 1 value UNION ALL
  SELECT 2 UNION ALL
  SELECT 3 UNION ALL
  SELECT 4 
) table1

Here is SQLFiddle demo

You can easily produce it in php like this using implode()

$myArr = array(1,2,3,4);

$sql="SELECT * FROM (SELECT ";
$sql .= implode(' value UNION ALL SELECT ', $myArr);
$sql .= ') table1';

Here is Codepad demo

0

solved mysql user defined variables as derived table