Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining two queries together

Status
Not open for further replies.

sdollen

Technical User
Oct 12, 2002
24
US
I created a contact database where I track contacts based on visits to a customer and seeing a customer at a conference in two tables (visit and conference).

I ran two queries for both tables against a customer name table and pulled the unmatched on the visit and conference tables.

This gives me two queries which shows me who hasn't had a visit or hasn't been to a conference.

Make sense so far? And, yes I'm sure my table structure isn't the best ;)

Now, how can I do a union between the two queries so I can see who hasn't had a visit AND hasn't been to a conference?

Thank you for any help. This is truly a GREAT forum.
 
Hmm.... I was sitting here thinking about my post..and actually, I don't need to know who hasn't had a visit AND who hasn't been to a conference.

I need to figure out how hasn't had a visit OR who hasn't been to a conference.

That would still be the union of the two queries though.. wouldn't it? It's late in the day to think ;)

-Stefan
 
yes, you could do it with a union

Code:
select username
  from usertable
 where not exists
       ( select 1 
           from visits
          where visits.userid = usertable.userid )
union
select username
  from usertable
 where not exists
       ( select 1 
           from confs
          where confs.userid = usertable.userid )

on the other hand, you can do it in one query too, just put those two conditions into one WHERE clause -- then you could also decide whether you wanted AND or OR

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top