Stupid mysql question.... syntax error?

Crusty

Lifer
Sep 30, 2001
12,684
2
81
INSERT INTO `dividends` ( `symbol_id` ) VALUES(SELECT `id` FROM `symbols` WHERE `name` = 'ADBE');

Im running mysql 4.1 so sub queries are allowed....

I'm pretty sure it's a glaringly obvious mistake... i need sleep :(

#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 `id` FROM `symbols` WHERE `name` = 'ADBE')' at line 1

That's what mysql spits out at me...
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Haven't done this sort of thing in a while but iirc, you're not supposed to have the VALUES keyword there (just ()s around the SELECT).
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: kamper
Haven't done this sort of thing in a while but iirc, you're not supposed to have the VALUES keyword there (just ()s around the SELECT).

Yeah, I was just about to ask about that. It seems that if you are doing a sub query you don't need VALUES, only ifyou are hardcoding the values
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Yeah..

INSERT INTO `dividends` ( `symbol_id` ) SELECT `id` FROM `symbols` WHERE `name` = 'ADBE' works fine.