?
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
Medium Priority
?
291 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 78

Accepted Solution

by:
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
)
/

Open in new window

0
 

Author Closing Comment

by:SQLnewbie77
ID: 39606362
thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

809 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