oracle sql query finding rows with multiple values in 3rd column matching columns 1 and 2

Jeff Kish

I have a dataset with about a million rows in and Oracle 11 db. I'd like to find rows where col1 and col2 match but have different values in col3. I'm not sure how to do this well though i can certainly write a query that never seems to finish:

select col1,col2,col3 
from table tab1 
where exists 
(select 1 
from table tab2 
where tab1.col1 = tab2.col1 
  and tab1.col2 = tab2.col2 
  and tab1.col3 != tab2.col3);

I ran this and after an hour gave up waiting - I need to analyze the problems and present it to some people for figuring out how to move forward.

Thanks in any case, Jeff

Glenn

A query like this will indicate which rows having the same col1, col2 have differing values in col3:

SELECT col1, col2
  FROM x
  GROUP BY col1, col2
  HAVING MIN(col3) <> MAX(col3)

To see how many of this col1, col2 pairs are affected:

SELECT COUNT(*)
  FROM (SELECT col1, col2
          FROM x
          GROUP BY col1, col2
          HAVING MIN(col3) <> MAX(col3)
        )

You may also wish to know how many duplicates there are (ie having col1, col2, col3 the same:

SELECT col1, col2, col3
  FROM x
  GROUP BY col1, col2, col3
  HAVING COUNT(*) > 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do I query for all rows but limit by max values of two columns when 3rd column is of a specific value in one single query?

From Java

Group by 2 columns with calculation of quantile of 3rd numerical column

From Dev

SQL Query finding field with multiple rows

From Dev

Finding rows with multiple values in the columns

From Dev

In SQL, I need to generate a ranking (1st, 2nd, 3rd) column, getting stuck on "ties"

From Dev

SQL query to check multiple values of multiple columns

From Dev

Finding Null values in multiple columns in SQL

From Dev

Oracle SQL: Transform rows to multiple columns

From Dev

How to get the 3rd column in an array by using 1st and 2nd column values as index in Matlab

From Dev

SQL / ActiveRecord Query for Multiple Rows on Multiple Columns

From Dev

Awk comparing 3 values, 2nd file value between 1st file values with multiple column printout between both files to a 3rd

From Dev

SQL Oracle - sum values in columns in first table using column names that are stored as values (rows) in second table

From Dev

SQL Query Dividing 1 column to 3 columns

From Dev

comparing values of 2 columns from same pandas dataframe & returning value of 3rd column based on comparison

From Dev

Matching values with multiple columns

From Dev

SQL Query finding field with multiple rows

From Dev

bash - merging 2 files using 2 common columns and add up the values of the 3rd column

From Dev

Select multiple column values in single query - oracle

From Dev

In SQL, I need to generate a ranking (1st, 2nd, 3rd) column, getting stuck on "ties"

From Dev

SQL query to check multiple values of multiple columns

From Dev

SQL Query for finding rows with same set of values

From Dev

Oracle SQL: Transform rows to multiple columns

From Dev

Awk comparing 3 values, 2nd file value between 1st file values with multiple column printout between both files to a 3rd

From Dev

SQL Oracle - sum values in columns in first table using column names that are stored as values (rows) in second table

From Dev

SQL Query Dividing 1 column to 3 columns

From Dev

How can I add strings on the first 2 columns and add buttons on the 3rd column for each rows of strings in pyqt tablewidget?

From Dev

Pandas groupby 2 columns, select max of 3rd column

From Dev

Selecting multiple rows in a column into different columns (SQL)

From Dev

Return a 3rd column when 2 other columns match

Related Related

  1. 1

    How do I query for all rows but limit by max values of two columns when 3rd column is of a specific value in one single query?

  2. 2

    Group by 2 columns with calculation of quantile of 3rd numerical column

  3. 3

    SQL Query finding field with multiple rows

  4. 4

    Finding rows with multiple values in the columns

  5. 5

    In SQL, I need to generate a ranking (1st, 2nd, 3rd) column, getting stuck on "ties"

  6. 6

    SQL query to check multiple values of multiple columns

  7. 7

    Finding Null values in multiple columns in SQL

  8. 8

    Oracle SQL: Transform rows to multiple columns

  9. 9

    How to get the 3rd column in an array by using 1st and 2nd column values as index in Matlab

  10. 10

    SQL / ActiveRecord Query for Multiple Rows on Multiple Columns

  11. 11

    Awk comparing 3 values, 2nd file value between 1st file values with multiple column printout between both files to a 3rd

  12. 12

    SQL Oracle - sum values in columns in first table using column names that are stored as values (rows) in second table

  13. 13

    SQL Query Dividing 1 column to 3 columns

  14. 14

    comparing values of 2 columns from same pandas dataframe & returning value of 3rd column based on comparison

  15. 15

    Matching values with multiple columns

  16. 16

    SQL Query finding field with multiple rows

  17. 17

    bash - merging 2 files using 2 common columns and add up the values of the 3rd column

  18. 18

    Select multiple column values in single query - oracle

  19. 19

    In SQL, I need to generate a ranking (1st, 2nd, 3rd) column, getting stuck on "ties"

  20. 20

    SQL query to check multiple values of multiple columns

  21. 21

    SQL Query for finding rows with same set of values

  22. 22

    Oracle SQL: Transform rows to multiple columns

  23. 23

    Awk comparing 3 values, 2nd file value between 1st file values with multiple column printout between both files to a 3rd

  24. 24

    SQL Oracle - sum values in columns in first table using column names that are stored as values (rows) in second table

  25. 25

    SQL Query Dividing 1 column to 3 columns

  26. 26

    How can I add strings on the first 2 columns and add buttons on the 3rd column for each rows of strings in pyqt tablewidget?

  27. 27

    Pandas groupby 2 columns, select max of 3rd column

  28. 28

    Selecting multiple rows in a column into different columns (SQL)

  29. 29

    Return a 3rd column when 2 other columns match

HotTag

Archive