Solved

t-sql look for records in two tables

Posted on 2016-11-07
2
54 Views
Last Modified: 2016-11-07
At this link
http://stackoverflow.com/questions/2686254/how-to-select-all-records-from-one-table-that-do-not-exist-in-another-table

I saw this example which selects all records from one table that do not exist in another table.
So it looks for the records in table t1 that do not exist in table t2

SELECT t1.name
FROM table1 t1
LEFT JOIN table2 t2 ON t2.name = t1.name
WHERE t2.name IS NULL


What's the syntax to look for records in two tables?
So look for the records in table t1 that do not exist in table t2 or table t3 ?

Anyone know?
0
Comment
Question by:maqskywalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 41877987
SELECT t1.name
FROM table1 t1
LEFT JOIN table2 t2 ON t1.name = t2.name
LEFT JOIN table3 t3 ON t1.name = t3.name
WHERE t2.name IS NULL or t3.name IS NULL

Open in new window

This is sometimes referred to as a "Left Excluding JOIN"
see: http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

Note if you only want rows in T1 that have no match in either t2 and t3 then change the OR to AND

SELECT t1.name
FROM table1 t1
LEFT JOIN table2 t2 ON t1.name = t2.name
LEFT JOIN table3 t3 ON t1.name = t3.name
WHERE t2.name IS NULL    and       t3.name IS NULL

Open in new window

1
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 41877993
thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

740 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