3

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.

3 Answers 3

5

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.' 
Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly, I didn't see that. Thanks for your help. I'm not getting any rows deleted, but the syntax is fine so I'm going to see what I did wrong otherwise. Thanks for the solution.
I was using a single apostrophe, despite you saying back tick. Works fine now. Thanks for the solution.
0

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.'

Comments

0

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.' 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.