SQL Query updating a range of fields - MySQL table

I am having some trouble forming this sql query. I want to run a mysql query as such:

Inside "TableX" I want to update "ColumnY" for all the entries in "ColumnZ" that has a value ranging from 2887 - 3474

Hope that was clear. I would run this in phpMyAdmin

Upvotes: 0

Views: 561

Answers (2)

ansh
ansh

Reputation: 696

Syntax for updating a record inside a table is

update <table_name>
set <column_name_1>=<new_value> [, <col_name_2>=<new_value_2> ...]
where <condition>;

So, your query will look like

update TableX  
set ColumnY='New Content'
where ColumnZ > 2886 and ColumnZ <3475;

Update

As mentioned by A C

If ColumnZ holds floating point number, then above query will return all such records where ColumnZ ∈ (2886,2887] and ColumnZ ∈ [3474,3475)

To model conditions in such cases, you should take care of the limits (inclusive or exclusive) and type of the column.

Upvotes: 0

Bor Laze
Bor Laze

Reputation: 2516

update TableX
set ColumnY = 'zzz'
where ColumnZ between 2887 and 3474

Upvotes: 1

Related Questions