Reputation: 470
SELECT
route_locations.id
FROM points JOIN route_locations ON route_locations.location_id = points.location_id
WHERE points.id in (199, 205)
group by route_locations.route_id
after running this query I am getting two value below:
id
1487
1491
first one is for points id 199 and second id is for points id 205.
Now as per my rule if first one is bigger than second one it will return 'HT'
else return 'RT'
how can I do that? if not possible how can I get the result like this?
point_id route_location_id
199 1487
205 1491
Upvotes: 0
Views: 43
Reputation: 780879
Use a self-join to get the two results separately, then compare them.
SELECT IF(l1.id > l2.id, 'HT', 'RT')
FROM points as p1
JOIN route_locations AS l1 ON p1.location_id = l1.location_id
CROSS JOIN points AS p2
JOIN route_locations AS l2 ON p2.location_id = l2.location_id
WHERE p1.id = 199
AND p2.id = 205
Upvotes: 1