Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

select records in one table not found in another?

Posted on 2013-06-04
3
Medium Priority
?
315 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
[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
3 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

660 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