Thursday, March 31, 2011

Is it possible to take the results of a SELECT and feed them into a VALUES clause?

For Example, is there any way to do something like the following:

INSERT INTO table2 VALUES(SELECT x FROM table1 WHERE x > 5 LIMIT 4)
From stackoverflow
  • Remove VALUES and the brackets:

    INSERT INTO table2 SELECT x FROM table1 WHERE x > 5 LIMIT 4
    
  • INSERT INTO SomeTable(column1, column2, column5)
    SELECT x as column1, y as column2, a as column5
    FROM differentTable
    WHERE ....
    

0 comments:

Post a Comment