?
Solved

My Except - intersect isn't working

Posted on 2011-04-19
4
Medium Priority
?
205 Views
Last Modified: 2012-05-11
How to select outside of intersection from these 2 tables?  Thanks.
select * from 
(select * from doctors 
union 
select * from person)
Except 
(select * from doctors 
intersect select * from person)

Open in new window

0
Comment
Question by:lapucca
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:sameer2010
ID: 35430064
You just need the following change:

select * from 
(select * from doctors 
union 
select * from person) T
Except 
(select * from doctors 
intersect select * from person)

Open in new window

0
 
LVL 13

Accepted Solution

by:
sameer2010 earned 2000 total points
ID: 35430083
Or try this...
select coalesce(doctors.id,'')+coalesce(person.id,'') as id from doctors full outer join person on doctors.id=person.id
where
doctors.id is null or person.id is null

Open in new window

0
 

Author Comment

by:lapucca
ID: 35434141
Hi, I ran the 1st query and got the following error
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

The 2nd query will not work because doctors.id and person.id are not of the same reference so their value will never equal to each other.  By the name you would assume they are but I'm merging 2 databases and that's why the PK are not related at all.  Thank you.
0
 

Author Closing Comment

by:lapucca
ID: 35942779
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question