Solved

select records in one table not found in another?

Posted on 2013-06-04
3
312 Views
Last Modified: 2013-06-04
dbo.postalcodes
dbo.populations

i want to select all postalcodes.CityName and postalcodes.ProvinceAbbr in dbo.postalcodes
that are not found as identical match in populations.City and populations.State

thanks!!
0
Comment
Question by:arthurh88
3 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 39221226
Select postalcodes.CityName, postalcodes.ProvinceAbbr
FROM postalcodes LEFT JOIN populations
ON postalcodes.CityName = populations.City AND postalcodes.ProvinceAbbr = populations.State
WHERE populations.City IS NULL AND populations.State IS NULL

Open in new window

0
 
LVL 41

Expert Comment

by:Sharath
ID: 39221236
You can also try this.
select *
  from postalcodes pc
 where not exists (select 1 
                     from populations p 
					where pc.CityName = p.CityName 
					  and pc.ProvinceAbbr  = p.ProvinceAbbr)

Open in new window

0
 

Author Closing Comment

by:arthurh88
ID: 39221247
thanks!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

679 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