问题描述
我有3张桌子
1是个人
第二个是国家
和州
在个人表中,我维护了国家和州的ID这样的
ID姓名电子邮件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
我的问题是在显示人员表而不是CID和SID的输出时,我想显示两个表中的名称为此我写了这样的查询,但它没有显示正确的结果。
这是我的查询
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
0aa22432322
144444
2qwqw121212
3sdsd333
444444
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
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.
推荐答案
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.
这篇关于如何在sql server的Output中的Person表中显示国家名称和状态名称而不是ID。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!