Reputation: 467
I have a table called person there are about 3 million rows
I have added a column called company_type_id whose default value is 0
now i want to update the value of company_type_id to 1
where person_id from 1 to 212465 and value of company_type_id to 8 where person_id from 256465 to 656464
how can i do this
I am using mysql
Upvotes: 0
Views: 33
Reputation: 32713
You can do that in one update statement:
update person
set company_type_id = 1
where
(person_id >= 1 and person_id <= 212465) or
(company_type_id = 8 and person_id >= 256465 and person_id <= 656464)
Upvotes: 1
Reputation: 5291
Two SQLs:
1:
UPDATE person
SET company_type_id = 1
WHERE person_id BETWEEN 1 AND 212465
2:
UPDATE person
SET company_type_id = 8
WHERE person_id BETWEEN 256465 AND 656464
Upvotes: 0
Reputation: 1123
update person set company_type_id=1 where person_id>=1 and person_id<=212465;
I am sure you'll make the second update query by yourself.
Upvotes: 0