views:

27

answers:

3
INSERT IGNORE INTO table3
(id1,   id2) VALUES
SELECT id1, id2 FROM table1, table2;

What's wrong with the above SQL query?

It shows me syntax error.

+4  A: 

Remove the word VALUES. See here for spec:

INSERT IGNORE INTO table3
(id1,   id2) 
SELECT id1, id2 FROM table1, table2;

And note Russ' response.

RedFilter
Thanks a lot. Unfortunately i did not care about it. :(
Saiful
@Saiful: what is this *it* that you refer to?
RedFilter
+1  A: 

Remove "VALUES".

Oh, and by the way, you've got a cartesian join. You should add syntax to join table1 to table2.

Russ
+1 for catching the cartesian join. That could cause a lot of pain... unless OP actually *wants* that...
FrustratedWithFormsDesigner
Oh yeah--if table1 has 100 rows, and table2 has 50 rows, table3 will have 5000 new rows!
Russ
A: 

try this

INSERT IGNORE INTO table3(id1,   id2) 
SELECT id1, id2 FROM table1, table2;

VALUES is not used in combination with a SELECT statement

SQLMenace