Solved

SQL Select where not exists?

Posted on 2012-12-26
2
586 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
ID: 38722275
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
ID: 38722296
Thanks
Buried and can't remember the simplest thing
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

910 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

24 Experts available now in Live!

Get 1:1 Help Now