A.N.M. Saiful Islam
A.N.M. Saiful Islam

Reputation: 2138

MySQL INSERT - SELECT syntax problem!

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.

Upvotes: 2

Views: 886

Answers (3)

SQLMenace
SQLMenace

Reputation: 135171

try this

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

VALUES is not used in combination with a SELECT statement

Upvotes: 0

Russ
Russ

Reputation: 4173

Remove "VALUES".

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

Upvotes: 2

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171579

Remove the word VALUES. See here for spec:

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

And note Russ' response.

Upvotes: 5

Related Questions