database - a nested query question in mysql -
i'm trying learn nested queries in mysql , i'm stuck while selecting hotels 30 miles away city , have rooms cost 150$
i can chose rooms 30 miles away city , costs 150 query,but can't reach hotels.
(select id rooms cost = 150 , id in (select r_id has_rooms name in (select name is_at l_town in (select town location distance_from_city = 30)))); rooms +----+------+---------+ | id | cost | type | +----+------+---------+ | 1 | 100 | kral | | 2 | 0 | kralice | | 3 | 150 | padisah | | 4 | 150 | hop | | 5 | 150 | boss | +----+------+---------+ has_rooms +------+------+ | r_id | name | +------+------+ | 1 | | | 2 | b | | 3 | c | | 4 | | | 3 | | +------+------+ is_at +------+----------+ | name | l_town | +------+----------+ | | istanbul | | b | izmir | | c | kars | | d | adana | +------+----------+ select * location; +--------------------+----------+----------------+----------+ | distance_from_city | postcode | street | town | +--------------------+----------+----------------+----------+ | 30 | null | kennedy street | istanbul | | 35 | null | null | kars | | 40 | null | tenesse | izmir | | 50 | null | null | adana | +--------------------+----------+----------------+----------+ hotel +------+--------+ | name | rating | +------+--------+ | | 5 | | b | 5 | | c | 4 | | d | 1 | +------+--------+
select h.* hotel h join is_at ia on ia.name = h.name join location l on l.town = ia.town exists ( select null rooms r join has_rooms hr on hr.r_id = r.id hr.name = h.name , r.cost = 150 ) , distance_from_city <= 30
Comments
Post a Comment