SQL Query for Inserting Data
5 June 2008
You can find some SQL query examples for inserting data using INSERT statements.
Inserting Values to Table
INSERT INTO table1 (field1,field2,field3)
VALUES (value1,value2,value3)
VALUES (value1,value2,value3)
Be aware that inserted values should have the same field type with coresponding fields.
Inserting records with SELECT
INSERT INTO table_a
SELECT field1, field2 FROM table_b
SELECT field1, field2 FROM table_b
Numbers of fields in table_a have to be the same with fields number from the SELECT statement. They also have to be the same field type.
Inserting certain fields with SELECT
INSERT INTO table_a (field1, field2)
SELECT srcfield1, srcfield2 FROM table_b
SELECT srcfield1, srcfield2 FROM table_b
Numbers of fields in table_a have to be same with number of fields from table_b. Srcfield1 should have the same field type as field1.