Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a range of records in Mysql

Tags:

mysql

I have a table that I am trying to update a range records, I have tried multiple methods with no luck. Here is the scripts I've tried.

UPDATE va_categories SET is_showing = '1' WHERE category_id IS BETWEEN 1076 AND 1412;
UPDATE va_categories SET is_showing = '1' WHERE category_id > '1076' < '1412';

The category_id is a Integer field.

I would appreciate an help, banging my head here.

like image 391
user3099756 Avatar asked Dec 19 '13 16:12

user3099756


2 Answers

Try this

UPDATE va_categories SET is_showing = '1' WHERE category_id  BETWEEN 1076 AND 1412;

or

 UPDATE va_categories SET is_showing = '1' WHERE category_id > 1076 AND category_id < 1412
like image 162
johnny Avatar answered Oct 13 '22 12:10

johnny


Here is the directive for range in MySQL:

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

Hence, this works:

UPDATE va_categories SET is_showing = '1' WHERE category_id BETWEEN 1076 AND 1412;
like image 25
Victor Avatar answered Oct 13 '22 11:10

Victor