Home All Groups Group Topic Archive Search About

Help with SELECT statement

Author
12 Nov 2005 3:33 PM
Niclas
Hi,

I have two tables with a UserID column and need to construct a query that
lists all UserIDs from Table A that is not present in Table B.

Any help with this select statement would be appreciated

Niclas

Author
12 Nov 2005 3:52 PM
Sylvain Lafontaine
Select A.* from TableA as A where Not Exists (select * from TableB as B
where B.UserId = A.UserId)

You can also go with a Left Outer Join but it's a little more complicated to
understand:

Select A.* from TableA as A Left Outer Join TableB as B on A.UserId =
B.UserId
Where B.UserId is Null

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF


Show quote
"Niclas" <lindblom_nic***@hotmail.com> wrote in message
news:eipps755FHA.4076@tk2msftngp13.phx.gbl...
> Hi,
>
> I have two tables with a UserID column and need to construct a query that
> lists all UserIDs from Table A that is not present in Table B.
>
> Any help with this select statement would be appreciated
>
> Niclas
>
Author
12 Nov 2005 3:56 PM
Sylvain Lafontaine
A third possibility would be to use the IN clause:

Select A.* from TableA as A where A.UserId Not IN (select UserId from TableB
Where UserId is not Null)

The condition « Where B.UserId is Not Null » is a necessity if there is a
possibility that B.UserId can be Null; otherwise the result won't be good if
the IN clause encounter a Null value.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF


Show quote
"Niclas" <lindblom_nic***@hotmail.com> wrote in message
news:eipps755FHA.4076@tk2msftngp13.phx.gbl...
> Hi,
>
> I have two tables with a UserID column and need to construct a query that
> lists all UserIDs from Table A that is not present in Table B.
>
> Any help with this select statement would be appreciated
>
> Niclas
>
Author
12 Nov 2005 8:55 PM
Niclas
Many thanks !

Niclas

Show quote
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:emU3YG65FHA.2888@tk2msftngp13.phx.gbl...
>A third possibility would be to use the IN clause:
>
> Select A.* from TableA as A where A.UserId Not IN (select UserId from
> TableB Where UserId is not Null)
>
> The condition « Where B.UserId is Not Null » is a necessity if there is a
> possibility that B.UserId can be Null; otherwise the result won't be good
> if the IN clause encounter a Null value.
>
> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: http://cerbermail.com/?QugbLEWINF
>
>
> "Niclas" <lindblom_nic***@hotmail.com> wrote in message
> news:eipps755FHA.4076@tk2msftngp13.phx.gbl...
>> Hi,
>>
>> I have two tables with a UserID column and need to construct a query that
>> lists all UserIDs from Table A that is not present in Table B.
>>
>> Any help with this select statement would be appreciated
>>
>> Niclas
>>
>
>

AddThis Social Bookmark Button