List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 28 2003 12:12pm
Subject:Re: Syntax boggler
View as plain text  
At 2:33 -0400 4/28/03, Ken Tozier wrote:
>I'm attempting to insert values in a table where one of the fields 
>consists of the results of a select like so
>
>INSERT INTO publication (city_name, pub_code, pub_name, editor, pub_days)
>VALUES ((SELECT city.id FROM city WHERE city.city_name = 'Arlington' 
>AND city.state_abbr = 'ma'), 'AA', 'Arlington Advocate', 0, 
>'Thursday')
>
>When I run the "SELECT" by itself, it runs fine, but when embedded 
>in the "INSERT", I keep getting the following error
>
>ERROR 1064: You have an error in your SQL syntax.  Check the manual 
>that corresponds to your MySQL server version for the right syntax 
>to use near 'SELECT city.id FROM city WHERE city.city_name = 
>'Arlington' AND
>
>which tells me (I think) that MySQL doesn't like the 
>"city.state_abbr" field of the select. Anyone know how I can get 
>this to work?

When I'm unsure about statement syntax, I find it's often helpful
to check the manual.  In your case, you might want to read
this section; your syntax is somewhat off:

http://www.mysql.com/doc/en/INSERT_SELECT.html

>
>vitals:
>MySQL 4.0.12
>Mac OS 10.2.5
>
>Thanks,
>
>Ken


-- 
Paul DuBois
http://www.kitebird.com/
sql, query
Thread
Syntax bogglerKen Tozier28 Apr
  • Re: Syntax bogglerPaul DuBois28 Apr
Re: Syntax bogglerMarek Lewczuk28 Apr