.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

getting information from the reference table

Posted By: Rajesh     Posted Date: April 02, 2010    Points:2   Category :Sql Server
I am having table like
eid ename did
1 xxx 101
2 yyy 102
3 zzz 103
but here i am having another table which is referred through foriegn key
did dname
101 ddd
102 aaa
here i am not specifying the 103 row in 2nd table. now i want the information of both tables with including 103 row also

Responses
Author: Dilip             
Posted Date: April 02, 2010     Points: 5   

LeftTab
===============
eid ename did
1 xxx 101
2 yyy 102
3 zzz 103

RightTab
==============
did dname
101 ddd
102 aaa

You need to have left outer join which gives all the common data from both tables and extra data from left table.

SELECT lt.eid, lt.ename,lt.did,rt.dname
FROM LeftTab lt
LEFT OUTER JOIN RightTab rt
ON lt.did = rt.did


Regards
Dilip
Author: Rajesh             
Posted Date: April 09, 2010     Points: 5   

Thank for ur replay

Author: Rajesh             
Posted Date: April 09, 2010     Points: 5   

thank u for replay and one more thing is it's returning the 103 details in first table

Author: Dilip             
Posted Date: April 09, 2010     Points: 5   

Yes ofcourse, the output of this table would be

eid ename did dname
1 xxx 101 ddd
2 yyy 102 aaa
3 zzz 103 null

Regards
Dilip


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend