Solved

How to SELECT from foreign table where criteria matches or return a null but only joining on one null.

Posted on 2015-02-17
2
96 Views
Last Modified: 2015-02-17
Given
TableA
ID     Name
1         A
2         B
3         C
4         D
5         E

and

TableB
ID   CategoryID  
1        5
2        4
2        5
3        5
3        4
4        1
4        3
and joining the two tables above and applying some criteria somewhere in the selection of CategoryID = 5 I would like to get output column :

TableC
ID  Name  CategoryID  
1        A           5
2        B           5
3        C           5
4        D          null
5        E           null

Note that ID only returns once and basically we get the category id returned if there is a match but otherwise null.
I would prefer to avoid using grouping although you may say this is not possible.
Server is SQL server 2000
Thanks in advance!
0
Comment
Question by:dgloveruk
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40613793
Select A.ID as ID, A.Name as Name, B.CategoryID as CategoryID
From TableA as A
left join (Select ID, CategoryID from TableB where CategoryID = 5) as B
on A.ID = B.ID
0
 

Author Closing Comment

by:dgloveruk
ID: 40614069
That's great , thanks very much!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question