Solved

Query several fields in one table from another table

Posted on 2013-12-03
2
287 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
2 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

911 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

25 Experts available now in Live!

Get 1:1 Help Now