Ninad Ninad - 1 year ago 139
SQL Question

How to write query to get names of primary keys

Table structure :

location_id name
1 Location1
2 Location2
3 Location3

tour_available_id from_location to_location
1 2 3
2 1 2
3 2 1

In above table from_location and to_location are foreign_keys(Which is primary key in Location table)

I want output as:

Expected output
from_location to_location
Location2 Location3
Location1 Location2
Location2 Location1

Answer Source
select as frm_location, as t_location 
  from Tour_available as TA INNER JOIN Location as FL ON (FL.location_id = TA.from_location) 
    INNER JOIN Location as TL ON (TL.location_id = TA.to_location);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download