How to get source and destination city name using inner query in mysql -
table_cities - city_id, city_name table_booking - booking_id, source_city_id, destination_city_id
i want booking_id | source_city_name | destination_city_name result.
i trying this:
select * table_bookings inner join table_cities on table_bookings.source_city_id = table_cities.city_id inner join table_cities on table_bookings.destination_city_id = table_cities.city_id;
but giving not unique table/alias: 'table_cities'
can help?
you need add aliases query, because join on table table_bookings twice
, select *
table names ambiguous, need add aliases after joins make clear:
select table_bookings.booking_id, sourcecities.source_city_name, destinationcities.destination_city_name table_bookings inner join table_cities sourcecities on table_bookings.source_city_id = table_cities.city_id inner join table_cities destinationcities on table_bookings.destination_city_id = table_cities.city_id;
Comments
Post a Comment