Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 tables
1 is Person
2nd is Country
and State

In person table i have maintained ids of Country and State like this
ID Name Email CID SID MobileNo
0 a a 2 24 32322
1 4 4 4 4 4
2 qw qw 12 12 12
3 sd sd 3 3 3
4 4 4 4 4 4


My question is while displaying the output from person table instead of CID and SID i want to display their Names from both tables for that i have written query like this but it is not displaying proper result.
this is my Query
SQL
select  condet.ContactID,condet.ContactName,condet.EMailID,tc.CName,ts.Name,condet.ContactNumber   from tblContactDetails as condet
                            left outer join tblCountry as tc on condet.CountryID = tc.CountryID
                            left outer join tblState as ts on tc.CountryID = ts.CountryID

So please suggest me how to display proper result with out duplicate.
Posted

1 solution

Ok it is working fine just i have to change table and column name while joining the table of state child.
SQL
select  condet.ContactID,condet.ContactName,condet.EMailID,tc.CName,ts.Name,condet.ContactNumber   from tblContactDetails as condet
                            left outer join tblCountry as tc on condet.CountryID = tc.CountryID
                            left outer join tblState as ts on condet.stateid = ts.stateid

Now it is working fine.
 
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