Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set all values in a single column MySQL Query

I've made a new tuple called 'description' in a table.

Just want a query to set all the 'description' tuples for my already created data to a certain piece of text.

E.g. of fundamental 'update' query, but not sure if it is not the right method to use:

UPDATE suppliers SET name = 'HP'WHERE name = 'IBM'; 

Any suggestions?

like image 438
cwiggo Avatar asked Nov 28 '12 18:11

cwiggo


2 Answers

The formatting of the query you've provided is correct. Before running an UPDATE or DELETE it's always wise to run a SELECT of that query to make sure that is the change you want to make.

Your test query would be:

SELECT name FROM suppliers WHERE name = 'IBM';

However, the query you've provided will not update the description column. To do this, you would need something like:

UPDATE suppliers SET description = 'HP' WHERE name = 'IBM';

After executing this UPDATE, you can run this query to validate your result:

SELECT name, description FROM suppliers WHERE name = 'IBM';
like image 71
Kermit Avatar answered Oct 22 '22 06:10

Kermit


Sorted

I Just used:

UPDATE suppliers SET description = 'business'

This setS all the description FIELDS in my table to the string "business".

Thanks for the suggestions.

like image 26
cwiggo Avatar answered Oct 22 '22 06:10

cwiggo