For MySQL, how to INSERT the result of a SELECT statement? For MySQL, how to INSERT the result of a SELECT statement? I tried

SET @input1 = 1;
SET @input2 = 2;
INSERT INTO
    my_table (col1, col2)
SELECT
    @input1 AS col1,
    @input2 AS col2
WHERE
    @input1 &gt; 0
        AND
    @input2 &gt; 0;


which gives a message:


  [42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE @input1 > 0 AND @input2 > 0' at line 6


Any idea how to fix it?

Here is a related article I found on this INSERT-SELECT approach to do conditional insert:

https://timmurphy.org/2013/10/23/conditional-insert-in-sql/

But it seems it does not work for MySQL which requires a FROM clause for SELECT?
The basic syntax for this generally involves inserting into one table by selecting from another, which would look something like:

INSERT INTO t1 (a1, b1)
     SELECT a2, b2 
       FROM t2
      WHERE a2 &gt; 0
            AND
            b2 &gt; 0
;


There is some flexibility in that, although perhaps not as much as you are looking for. It might be worth looking at the mysql docs for insert-select for more information.