September 20th, 2011, 01:39 PM
How do I retrieve results of this but not that?
I have a table "WR" that houses client information. I have another table "TR" that house information about services. I have a field "services" in the "TR" table that can have many codes if the client has received those services.
I would like to pull a query that shows me if the client has been in 1, 2, 3, 4 # codes BUT NOT IN 5. Is this possible?
Right now I would use the IN function to get the services I wanted to see, but if that client has received a 5 at any time, I don't want to see the client record at all.
September 20th, 2011, 02:14 PM
September 20th, 2011, 02:20 PM
Originally Posted by Vomster
from wr inner join tr on wr.id=tr.id
where tr.service IN ('1','2','3','4')
These shows me all clients who have had a service of 1 2 3 4. Which is great. But If they have had a service 5, I don't want to see any of their records.
September 20th, 2011, 04:24 PM
INNER JOIN tr ON wr.id=tr.id
tr.service IN ('1','2','3','4')
AND wr.id NOT IN
WHERE tr.service = '5'
September 20th, 2011, 05:33 PM
AWESOME! It worked perfectly. And makes complete sense. I have never worked with a subquery before and this helps put a lot of connections in place.
I appreciate the help so much!
September 21st, 2011, 08:37 AM