By lovehell


2020-01-14 13:02:28 8 Comments

Assuming I have such table

|---------------------|------------------|
|          ID         |       Name       |
|---------------------|------------------|
|          1          |         x        |
|---------------------|------------------|
|          ..         |         x        |
|---------------------|------------------|
|          N          |         x        |
|---------------------|------------------|

I need to change name fields to "z" for IDs between 30 and 100. Is there any way to use a loop or a while condition instead of doing this:

UPDATE table
SET Name = 'z'
WHERE ID = 30
OR ID = 31
OR ID = 32
...

2 comments

@Tim Biegeleisen 2020-01-14 13:05:44

You could use BETWEEN here:

UPDATE yourTable
SET Name = 'z'
WHERE ID BETWEEN 30 AND 100;

@RiggsFolly 2020-01-14 13:05:03

Simply specify that in the where clause

WHERE ID >= 30 AND ID <= 100

Related Questions

Sponsored Content

48 Answered Questions

[SOLVED] How do I import an SQL file using the command line in MySQL?

11 Answered Questions

[SOLVED] Can I concatenate multiple MySQL rows into one field?

24 Answered Questions

[SOLVED] How to reset AUTO_INCREMENT in MySQL?

10 Answered Questions

[SOLVED] How to 'insert if not exists' in MySQL?

25 Answered Questions

[SOLVED] How do you set a default value for a MySQL Datetime column?

  • 2008-10-03 20:24:30
  • Brian Boatright
  • 1287603 View
  • 905 Score
  • 25 Answer
  • Tags:   mysql datetime

39 Answered Questions

[SOLVED] Should I use the datetime or timestamp data type in MySQL?

8 Answered Questions

[SOLVED] How to shrink/purge ibdata1 file in MySQL

8 Answered Questions

[SOLVED] mysql update column with value from another table

11 Answered Questions

[SOLVED] MySQL - UPDATE query based on SELECT Query

Sponsored Content