Friday, February 24, 2012

Finally Got it to Work

I finally got it to work. Simple when you get it right. The working query is
below. I had been trying to use "NOT EXISTS" and I never did get that to
work? What is the difference between "Exists" and "IN"?
SELECT Distinct b.MemberName, b.MemberID
FROM Members AS b
WHERE b.MemberId NOT In
(SELECT Distinct MemberID
FROM EventRegs AS e)
Order By b.MemberName
Wayne
"Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
news:Oz30z0MzFHA.1168@.TK2MSFTNGP10.phx.gbl...
>I am using SQLServer 2000. I have one table (Members) which includes a
>MemberID (int) field. I have another table (EventRegs) with a unique
>EventID(int) and a foreign key for MemberID. A given MemberID can occur in
>more than one row in the EventRegs table. I want to find out which MemberID
>values that exist in the Members table that do not occur in any of the rows
>in the EventRegs table. Basically, which members are not attending any
>events.
> I always get tangled up when I try to do this type of query! Can anyone
> give me an example to work from?
> Wayne
>Wayne
> SELECT Distinct b.MemberName, b.MemberID
> FROM Members AS b
> WHERE b.MemberId NOT In
> (SELECT Distinct MemberID
> FROM EventRegs AS e)
> Order By b.MemberName
Using the above SELECT you can get a wrong output. What is a MemberID in
EventRegs is NULL ( at least one row)
"Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
news:OOYG4ANzFHA.1252@.TK2MSFTNGP09.phx.gbl...
>I finally got it to work. Simple when you get it right. The working query
>is below. I had been trying to use "NOT EXISTS" and I never did get that to
>work? What is the difference between "Exists" and "IN"?
> SELECT Distinct b.MemberName, b.MemberID
> FROM Members AS b
> WHERE b.MemberId NOT In
> (SELECT Distinct MemberID
> FROM EventRegs AS e)
> Order By b.MemberName
> Wayne
>
> "Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
> news:Oz30z0MzFHA.1168@.TK2MSFTNGP10.phx.gbl...
>|||Good point Uri but in this particular case, the MemberID can never be null.
Wayne
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:%23m86yHNzFHA.3860@.TK2MSFTNGP09.phx.gbl...
> Wayne
> Using the above SELECT you can get a wrong output. What is a MemberID in
> EventRegs is NULL ( at least one row)
>
> "Wayne Wengert" <wayneSKIPSPAM@.wengert.org> wrote in message
> news:OOYG4ANzFHA.1252@.TK2MSFTNGP09.phx.gbl...
>

No comments:

Post a Comment