Query syntax to select ALL minus results from another query

I have two queries. One will return 'all users' of a certain kind (usertype), the other will return a portion of those users that are linked to a 'case'.
The query I need is the results of query # 1, minus the results of query # 2, to avoid them for being duplicated when I display them on the screen.

Query # 1

SELECT *
FROM dbo.Users
WHERE (users.Usertype='attorney' or users.Usertype= 'paralegal') and archivedcont = 0

Query # 2

SELECT *
FROM dbo.Atts
INNER JOIN Users ON atts.userid = users.userid
WHERE CaseId = MMColParam and email IS NOT NULL and email <> '' and users.archivedcont = 0 and  (users.Usertype='attorney' or users.Usertype= 'paralegal')
LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RayData AnalystCommented:
So you want all users NOT linked to a case, correct?
0
RayData AnalystCommented:
If my earlier question was correct, this code should do it (although it may not be the most efficient way).

Basically, it just takes your list of all users, then says where the user is not in query2.  That leaves the rest of the users.

SELECT *
FROM dbo.Users
WHERE (users.Usertype = 'attorney' OR users.Usertype = 'paralegal') AND archivedcont = 0 AND users.userid NOT IN (
            SELECT users.userid
            FROM dbo.Atts
            INNER JOIN Users ON atts.userid = users.userid
            WHERE CaseId = MMColParam AND email IS NOT NULL AND email <> '' AND users.archivedcont = 0 AND (users.Usertype = 'attorney' OR users.Usertype = 'paralegal'
                        )
            )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
Trying now ..
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

AleksAuthor Commented:
Awesome !!!  Thank you !
0
awking00Commented:
select * from dbo.users
where usertype in ('attorney','paralegal')
and archivedcont = 0
and not exists
(select 1 from dbo.atts
 where caseid = MMColParam
 and email is not null and email <> ''
 and userid = users.userid);
0
AleksAuthor Commented:
Sorry forgot to assign the points
0
RayData AnalystCommented:
Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.