Skip to content
Advertisement

Oracle 11g SQL Query – Specify which duplicates to Exclude from Select Statement

I have a question about excluding duplicate values with my Oracle SQL query. Using select distinct does not work in this case. I only want to select one row for each event#, the row where Mobile = Yes.

Actual Result of Current Query:

Desired Result:

In this ideal result, one of the rows for Event# 1 has not been selected – the one kept is where Mobile = Y. Is it possible to exclude a duplicate, but control which row is kept and which is not? (In this case, I want to keep the row where Mobile = Y in the result). The solution cannot be specific to this one Event#, as this is just a small excerpt/example of the data from a table with thousands of rows, and hundreds of cases where these duplicates occur. Deleting records from the table is not an option either.

Current SQL Query:

Any advice will be greatly appreciated!

Advertisement

Answer

I think you can use a window function here –

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement