2014-12-14 2 views
0
에 두 개의 문자열 값의 행을 얻는 방법을

내 표는 다음과 같습니다는 MySQL의

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

나는이 개 도시와 road_id의 값을 알고이 같은 필요 : 그래서

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 
+0

을 "London"과 "Glasgow"사이의 이름이있는 도시가 아닌 ID (런던, 포함)와 ID (글래스고, 배타적) 사이의 ID를 가진 행을 (이 경우 업데이트를 위해) 선택하고 싶습니까? –

답변

1
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