View Full Version : Query syntax

January 9th, 2009, 02:20 AM

Can any db experts point out what is wrong here? I have tested the select subquery alone, it works fine, looked at examples in mysql manual on subqueries, it looks the same too... yet mysql gives a syntax error when I try running it:

INSERT IGNORE INTO `static_data` (`name`, `maintainer`) VALUES (SELECT `name`, `maintainer` FROM `all_applications`);

January 9th, 2009, 07:35 AM
Knowing the error message might help in finding the cause of the error.

January 9th, 2009, 10:22 AM

Judging by this page, you need to lose the VALUES keyword and the brackets, like so

INSERT IGNORE INTO `static_data` (`name`, `maintainer`)
SELECT `name`, `maintainer` FROM `all_applications`;

January 9th, 2009, 02:12 PM
see http://www.w3schools.com/SQL/sql_insert.asp

column names cannot be string literals

INSERT IGNORE INTO static_data (name, maintainer)
VALUES (SELECT name, maintainer FROM all_applications);

BTW you should read "how to ask questions" in my sig: provide error message, and use CODE tags, not QUOTE so we can quote you :-)

January 9th, 2009, 04:46 PM
Didn't provide the error message 'cause I couldn't copy.

Thanks a bunch, the query works now, but the 'ignore' part does not:


Manual just says "Specify IGNORE to ignore rows that would cause duplicate-key violations.". Does that not apply to test fields?