Bajlo
Bajlo

Reputation: 1427

how to get rows between two string values in mysql

My table looks like this:

id   city         road_id
-------------------------
1    london       3
2    manchester   3
3    newcastle    3
4    glasgow      3
5    london       5
6    newcastle    5

I know values of two cities and road_id and need something like this:

UPDATE table SET anothercolumn=1 WHERE id>=(id for)london AND id<(id for)glasgow AND road_id=3

to affect only these rows:
1    london       3
2    manchester   3
3    newcastle    3

Upvotes: 0

Views: 648

Answers (1)

juergen d
juergen d

Reputation: 204904

UPDATE your_table 
SET anothercolumn = 1 
WHERE id >= (select id from your_table where city = 'london')
AND   id <  (select id from your_table where city = 'glasgow')
AND road_id = 3

Upvotes: 1

Related Questions