Solved

SQL Select where not exists?

Posted on 2012-12-26
2
580 Views
Last Modified: 2012-12-26
(Simplified)
I have a view with the following 4 fields

ClientID   ContactID    ContactType   FullName


I want to do a UNION all and
Select  ClientID, ContactID,ContactType,FullName
From ClientContacts

Where the ClientCOntacts record doesn't exist in the View

The similar fields are of course ClientID and ContactID
0
Comment
Question by:lrbrister
2 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 500 total points
Comment Utility
select  ClientID, ContactID, ContactType, FullName
from ClientContactsView C
union all
select  ClientID, ContactID, ContactType, FullName
from ClientContacts C
where not exists (
  select 1
  from ClientContactsView C1
  where C.ClientID = C1.ClientID and C.ContactID = C1.ContactID
)

Open in new window

0
 

Author Closing Comment

by:lrbrister
Comment Utility
Thanks
Buried and can't remember the simplest thing
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now