views:

51

answers:

1

I wrote this simple query statement:

INSERT INTO merchants 
('firstName','lastName') 
VALUES 
('Bob','Smith')

Sounds very simple but I keep getting this 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 ''firstName','lastName' ) VALUES ('Bob','Smith' )' at line 2

+4  A: 

You need to remove the quotes from around firstName and lastName:

INSERT INTO merchants 
(firstName,lastName) 
VALUES 
('Bob','Smith')

Column names are identifiers, and as such are not quoted.

Edit: Column names can be quoted using backticks (`), but this is only necessary if you have column names that contain special characters or column names that match MySQL keywords.

James McNellis
If you have to quote the column names use backticks (`) in Mysql.
Kris Erickson
I'm guessing you might have been copying the syntax from somewhere and mistaken the backticks (`) that can be used to delimit column or table names from the single quotes (') that delimit string literals.
Tenner
Now, that works. Thank you!
netrox
Thank you, Kris. I've added that note to the answer. You're welcome, netrox.
James McNellis