order - MySQL Where Clause - get two cities where ID of 1. row < ID of 2. row -
i have 2 tables:
1) table travels
id | title ------------------------ 1 | travel1 2 | travel2 3 | travel3 2) table cities
id | city | travel_id ------------------------ 1 | london | 1 2 | york | 1 3 | newcastle | 1 4 | london | 2 5 | newcastle | 2 6 | newcastle | 3 7 | york | 3 id of cities means order.
so question is: how can travels if cities (from b) declared. (e.g. york newcastle should travel1, london newcastle - travel1 , travel2)
if understand correctly, want travel ids id of first city less id of second.
if so, may looking for:
select c1.travelid cities c1 bring together cities c2 on c1.city = $city1 , c2.city = $city2 , c1.travelid = c2.travelid , c1.id < c2.id; if want name, can bring together in:
select t.* travels t bring together cities c1 on c1.travelid = t.travelid bring together cities c2 on c1.city = $city1 , c2.city = $city2 , c1.travelid = c2.travelid , c1.id < c2.id; mysql order where rows having
No comments:
Post a Comment