Okay, having some trouble getting [NOT] EXISTS working with my one-table
example.  No more colors etc, here is the actual code.  Basically, I have a
table:

UserCredentials:
  UserID: int
  CredentialNumber: int
  Description: varchar

I want to find the UserID of all users who have a "Keypad" credential, but
do *not* have a "Magnetic Stripe Card" credential.

Here is my latest try, but unfortunately it returns all rows in the table,
not just the keypad-only ones:

SELECT UserID as id, Description from dbo.UserCredentials WHERE
EXISTS (
  SELECT * FROM dbo.UserCredentials WHERE UserID = id AND Description =
'Keypad'
)
AND NOT EXISTS (
  SELECT * FROM dbo.UserCredentials WHERE UserID = id AND Description =
'Magnetic Stripe Card');

I think I'm getting confused about how to get the "iterating" user id into
the conditions?

-glenn

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to