Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have to tables City Table and Employee table
in City Table is contain:
1- CityID.(PrimaryKey)
2- CityName.
in Employee Table is contain:
1- EmployeeID.
2- CurrentCityID.(foreignkey )
3- PreviousCityID. (foreignkey)

i want make sql query that bring Name of Current City and Previous City

thx
Posted

1 solution

Try
SQL
SELECT EmployeeID, C1.CityName AS CurrentCity, C2.CityName AS PreviouCity
FROM  Employee E
LEFT JOIN  City C1 ON E.CurrentCityID = C1.CityID
LEFT JOIN  City C2 ON E.PreviousCityID= C2.CityID
 
Share this answer
 
Comments
Member 8194711 26-Dec-12 8:23am    
thank you very much...
__TR__ 26-Dec-12 8:52am    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900