Link to home
Start Free TrialLog in
Avatar of Wilder1626
Wilder1626Flag for Canada

asked on

Oracle - query to return diffrences

Hi,

I have this table where 3 columns could have same information where the last 4 columns can sometime be the same and other times can have different values.

In below sample that you will also have in the attachment, you see that Brampton John Carson have 3 records but when you look at the columns Result1 to Result4, 2 rows are the same versus the other is different.

As for Ajax Bruce Saxton, Result1 to Result4 have the same values on both rows.

The objective for me is to only extract from the table when i have the same value from City, Name and Family name and when i have more then 1 difference in columns Reult1 to Result4.

Example. If my table got:
User generated image
The query result would return:
User generated image
How can i do that?

Thank you for your help
Table1.xlsx
Avatar of Sean Stuber
Sean Stuber

SELECT city, name, family_name, result1, result2, result3, result4
  FROM (SELECT t.*,
               COUNT(DISTINCT result4) OVER (PARTITION BY city, name, family_name) cnt,
               ROW_NUMBER() OVER(PARTITION BY city,name,family_name,result4 ORDER BY ROWNUM) rn
          FROM yourtable t)
 WHERE cnt != 1
   AND rn = 1

Open in new window

Avatar of Wilder1626

ASKER

Hi sdstuber,

is it only looking at result4 diffrences or all of the Results 1,2,3 and 4?
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's for your help. this is exactly what i was looking for.