I am trying to INSERT INTO
a table using the input from another table. Although this is entirely feasible for many database engines, I always seem to struggle to remember the correct syntax for the SQL
engine of the day (MySQL, Oracle, SQL Server, Informix, and DB2).
Is there a silver-bullet syntax coming from an SQL standard (for example, SQL-92) that would allow me to insert the values without worrying about the underlying database?
Looks nice, but works only if tmp doesn't exists (creates it and fills). (SQL sever)
To insert into existing tmp table:
Just use parenthesis for SELECT clause into INSERT. For example like this :
Most of the databases follow the basic syntax,
Every database I have used follow this syntax namely,
DB2
,SQL Server
,MY SQL
,PostgresQL
Here is another example where source is taken using more than one table:
Instead of
VALUES
part ofINSERT
query, just useSELECT
query as below.You could try this if you want to insert all column using
SELECT * INTO
table.