Excluding Rows Based on Column Contents
I'm trying to write a query which will exclude rows based on their common value in a particular column if a value in another column exists. Essentially:
SELECT Phone, Name, Age FROM Customer WHERE etc etc etc
What I would like to do is: If, for example, one customer's information would be: 111-222-3333, Rick, 45, and for whatever reason 45 is the particular value for which if it exists, I'd like to exclude all subsequent rows which match that corresponding telephone number, how would I do this?
Sounds like a WHERE NOT EXISTS may work here,
SELECT Phone, Name, Age FROM Customer C WHERE NOT EXISTS ( SELECT * FROM Customer M WHERE M.Age = 45 AND M.Phone = C.Phone )