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

x
?
Solved

Query several fields in one table from another table

Posted on 2013-12-03
2
Medium Priority
?
299 Views
Last Modified: 2013-12-03
Hi,

I have a table looking like this:
customerID int
firstname
lastname
address
zip
city

Then I have a second table looking like this:
id
name (Smith, John)
adress
zip
city

what I need to do is to get all records from the first table that are not part of the second one based on firstname, lastname and city. The name is stored in a firstname and a lastname in the first but they are in one column in the second.

How can I accomplish this in a query?

Peter
0
Comment
Question by:peternordberg
[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
2 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 39692181
select * from firsttable A
where not exists(select 1 from secondtable B
           where A.lastname + ', ' + A.firstname = B.name
           and A.city = B.city)
0
 

Author Closing Comment

by:peternordberg
ID: 39692272
Thanks,

just what I needed.

Peter
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

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…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.

721 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