We help IT Professionals succeed at work.

My Except - intersect isn't working

Medium Priority
241 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

Comment
Watch Question

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

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Author

Commented:
Thank you
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.