SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with Join - Solved
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ssimon
Starting Member

USA
16 Posts

Posted - 04/17/2013 :  09:30:29  Show Profile  Visit ssimon's Homepage  Reply with Quote
I am transferring a Access db that a past employee built over to MS SQL 2008. I came across a couple of tables that I am trying to run a query against, but can not seem to get it to work.

TableA
Item Issue IssueDesc
2zw 5 FOO

TableB
Item Issue IssueDesc
2zw 20 BAR

TableC
Item Issue Fail
2zw 5 0
2zw 20 0

Select c.Item,a.IssueDesc as ThisIssue, b.IssueDesc as ThatIssue
FROM TableC as c
Inner Join TableA as a
On c.Issue = a.Issue
Inner Join TableB as b
On c.Issue = b.Issue
WHERE c.Item='2zw'

What I would like to return is:
Item ThisIssue ThatIssue
2zw FOO NULL
2zw NULL BAR

Edited by - ssimon on 04/17/2013 09:41:06

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 04/17/2013 :  09:36:38  Show Profile  Reply with Quote
--just change INNER JOIN to LEFT JOIN

Select c.Item,a.IssueDesc as ThisIssue, b.IssueDesc as ThatIssue
FROM TableC as c
LEFT Join TableA as a
On c.Issue = a.Issue
LEFT Join TableB as b
On c.Issue = b.Issue
WHERE c.Item='2zw'


--
Chandu

Edited by - bandi on 04/17/2013 09:37:55
Go to Top of Page

ssimon
Starting Member

USA
16 Posts

Posted - 04/17/2013 :  09:39:35  Show Profile  Visit ssimon's Homepage  Reply with Quote
Thank you...
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 04/17/2013 :  09:40:07  Show Profile  Reply with Quote
quote:
Originally posted by ssimon

Thank you...


Welcome

--
Chandu
Go to Top of Page

mmkrishna1919
Yak Posting Veteran

India
94 Posts

Posted - 04/17/2013 :  09:57:30  Show Profile  Reply with Quote
Try this..

Select c.Item,a.IssueDesc as ThisIssue, b.IssueDesc as ThatIssue
FROM #C as c
LEFT Join #A as a
On c.Issue = a.Issue
LEFT Join #B as b
On c.Issue = b.Issue
WHERE c.Item='2zw'

M.MURALI kRISHNA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000