PDA

View Full Version : Query syntax



Vadi
January 9th, 2009, 02:20 AM
Hi,

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`);

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

SupaSonic
January 9th, 2009, 10:22 AM
http://dev.mysql.com/doc/refman/5.1/en/insert-select.html

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`;

pmasiar
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 :-)

Vadi
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:

http://www.ubuntu-pics.de/bild/8111/screenshot_100_193__P03Ts6.png

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