Solved

SQL Select | Join tables where data not in second table

Posted on 2009-07-07
2
412 Views
Last Modified: 2012-05-07
SQL 2005
To simplify what I want to do...
I have table1 and table2.  I want to select the records in table1 that are not in table2.  I know I can do this by the following:
select t1.name, t1.address from t1 where t1.id not in (select t2.id from t2)

But is there a faster way?  The only field in t2 is "id".
0
Comment
Question by:ClowWater
2 Comments
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 100 total points
ID: 24795786
select t1.name, t1.address from t1
where NOT EXISTS (SELECT  1 FROM  t2 where t2.id = t1.id )

and sometimes LEFT JOINS are faster, but it depends
0
 
LVL 17

Accepted Solution

by:
pssandhu earned 150 total points
ID: 24795795
You can do it this if you are looking for a different way of doing this:
Select t.*
from  Table1 t LEFT OUTER JOIN Table2 c
           ON t.ID = c.ID
Where c.ID IS NULL
P.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

760 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

22 Experts available now in Live!

Get 1:1 Help Now