Solved

select records in one table not found in another?

Posted on 2013-06-04
3
310 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 24

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 40

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

816 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