Solved

select records in one table not found in another?

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Numeric sequence in SQL 14 38
SQL JOIN 6 37
search for a string in all tables 4 15
mySQL Syntax 7 0
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

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

16 Experts available now in Live!

Get 1:1 Help Now