Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

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

Posted on 2013-10-28
Medium Priority
290 Views
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
Question by:SQLnewbie77
[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

LVL 77

Accepted Solution

slightwv (䄆 Netminder) earned 2000 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
)
/
``````
0

Author Closing Comment

ID: 39606362
thanks!
0

## Featured Post

Question has a verified solution.

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

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
###### Suggested Courses
Course of the Month10 days, 19 hours left to enroll