Brian
Brian

Reputation: 159

how to delete a single value from mysql table

i have the following data in the table

name        price
red wine    150
white wine  300

i want to delete the value 300

i used the below query

update cms.wine set price =null where name='white wine'

it gives me the below error

You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.

Upvotes: 3

Views: 6960

Answers (2)

Over Killer
Over Killer

Reputation: 513

Use that:

DELETE FROM cms.wine WHERE price = '300' LIMIT 1

Upvotes: 1

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

Do like this:

SET SQL_SAFE_UPDATES=0;

and then:

update cms.wine set price =null where name='white wine;'

But you should do on the basis of id column as it will delete all records who has name equal to white wine

like this:

update cms.wine set price =null where id=1;

In this it will delete only that particular record which has primary key value 1.

you should add a primary key column in the table so that your table will look like this and make the column primary key so that its always unique for every record:

id      name          price
1       red wine      150
2       white wine    300

Upvotes: 4

Related Questions