Solved

How to query two tables to determine if at least one of the column values does not match

Posted on 2013-10-28
2
275 Views
Last Modified: 2013-10-28
I need to compare two tables to count how many emps have the same Applid, but might not have the same SSN, Gender, DOB, City of Birth or State of Birth. Its possible for them to have the same Applid, same Gender, but not SSN or same Applid, same DOB, but not City of Birth..pretty much any combination of the above.

Exact request: How many Applicant Ids where at least one of the following does not match - SSN, Gender, Date of Birth, City of Birth, State of Birth?

Applid table

Applid
Appl_FName
Appl_LName
SSN
Gender
Date of Birth
City of Birth
State of Birth

Person table
Applid
SSN
Gender
Date of Birth
City of Birth
State of Birth


I know to join the tables on Applid but after I am not sure how to proceed. Thanks in advance for the help
0
Comment
Question by:SQLnewbie77
2 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39606320
Try something like this:

create table tab1(col1 char(1), col2 char(1), col3 char(1)); 

drop table tab2 purge;
create table tab2(col1 char(1), col2 char(1), col3 char(1)); 


insert into tab1 values('a','a','a');
insert into tab1 values('b','a','b');
insert into tab1 values('c','c','a');

insert into tab2 values('a','a','a');
insert into tab2 values('b','b','a');
insert into tab2 values('c','a','c');
commit;


select t1.*, t2.*
from tab1 t1, tab2 t2
where t1.col1=t2.col1 and
(
	t1.col2 != t2.col2 or
	t1.col3 != t2.col3
)
/

Open in new window

0
 

Author Closing Comment

by:SQLnewbie77
ID: 39606362
thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

914 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

17 Experts available now in Live!

Get 1:1 Help Now