Click here to Skip to main content
15,851,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for example two columns of table1 , have relation to the id column of table2

for example:

tbl_city: (id , title)
tbl_person: (id , name , CurrentCityID , LastCityID , ...)

now , I want to make two relations from tbl_person to tbl_city
CurrentCityID and LastCityID must relation to tbl_city

this query is wrong:

SELECT , tbl_city.title , tbl_city.title
FROM tbl_person
JOIN tbl_city ON tbl_person.CurrentCityID =
JOIN tbl_city ON tbl_person.LastCityID =

can you help me ?

Yes it is possible.

Try this:
SELECT , tc1.title , tc2.title
FROM tbl_person
JOIN tbl_city tc1 ON tbl_person.CurrentCityID =
JOIN tbl_city tc2 ON tbl_person.LastCityID =
Share this answer
You need to identify which table to return results from

SELECT , C.title AS CurrentTitle, L.title AS LastCity
FROM tbl_person
JOIN tbl_city C ON tbl_person.CurrentCityID =
JOIN tbl_city L ON tbl_person.LastCityID =
Share this answer

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