taylorthurlow
taylorthurlow

Reputation: 3083

Proper mySQL syntax for DELETE, FROM, WHERE

I have a database with a table with 18 columns, the second of which is called "desc". I want to delete every row that has a certain value under "desc". I'm using this code:

DELETE FROM items WHERE desc='Swap this note at any bank for the equivalent item.'

Using this command inside of PHPMYADMIN gives me 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 'desc='Swap this note at any bank for the equivalent item.'' at line 1

I've looked around pretty well but I can't seem to find what I'm doing incorrectly.

mySQL version is 5.5, phpMyAdmin version is 3.4.5.

Upvotes: 3

Views: 2291

Answers (3)

John Woo
John Woo

Reputation: 263803

desc is a RESERVED WORD in MySQL

in order to escape Reserved Words, you must use back tick ( ` )

DELETE FROM `items` 
WHERE `desc`='Swap this note at any bank for the equivalent item.' 

Upvotes: 0

Aditya Naidu
Aditya Naidu

Reputation: 1380

Notice the back ticks. desc is a keyword in MySQL

DELETE FROM items WHERE `desc`='Swap this note at any bank for the equivalent item.'

Upvotes: 0

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171491

You'll need to use backticks around desc as it is the keyword for descending order when using ORDER BY:

DELETE FROM items 
WHERE `desc`='Swap this note at any bank for the equivalent item.' 

Upvotes: 5

Related Questions