Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with Join - Solved

Author  Topic 

ssimon
Starting Member

16 Posts

Posted - 2013-04-17 : 09:30:29
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

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-17 : 09:36:38
--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
Go to Top of Page

ssimon
Starting Member

16 Posts

Posted - 2013-04-17 : 09:39:35
Thank you...
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-17 : 09:40:07
quote:
Originally posted by ssimon

Thank you...


Welcome

--
Chandu
Go to Top of Page

mmkrishna1919
Yak Posting Veteran

95 Posts

Posted - 2013-04-17 : 09:57:30
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
   

- Advertisement -