Link to home
Start Free TrialLog in
Avatar of ZeppiP
ZeppiPFlag for Malta

asked on

SQL Query Question

Hi,

I need to wirte an sql query that pulls out info on clients. Now for each client record I have 2 codes for the countryID and nationalityID. I need to display both of them.

The problem I have is that these two fields point to the same table holding the data i need, As an example, assume I have the following:

ID 1 County Mallta Nationality Maltese
ID 2 Country UK Nationality British

Now I can have a client with a street address pointing to countryID 1, that is Malta, but a nationalituID of 2 = British.

Since now via left joins I added the country to the records I need to pull, but now I am stcuk as I want to add the nationality too.

Any Help is welcome, if you need further detail please just ask.
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for such condition you may use two joins as

Select * from yourTable
Inner Join tbl as Country On yourCondion
Inner Join tbl Nationailty  On yourCondion


if your data can be null then use left outer join as

Select * from yourTable
Left Outer Join tbl as Country On yourCondion
Left Outer Join tbl Nationailty  On yourCondion
Avatar of ZeppiP

ASKER

Perfect. Thanks mate. Did not know that you could join the same table more then once.