Skip to content
Advertisement

Distinct vs row_number() – query with same condition giving different result in oracle?

I am trying to eliminate duplicate based on combination of three columns on the same table with some filter conditions through two different approaches but for some reason the result of both are queries are not coming as same.

Query 1:

Result – 66181

Query 2:

Result – 65495

Shouldn’t the result of both the queries be the same ? Would be great if someone can tell me what am i doing wrong ?

Thanks, Kavin

Advertisement

Answer

The second query has conditions REC_CREATE_DT_KEY = 20191130 and MODEL_ID = 'ABC' in the outer query, while in the first query these are in the inner query.

Move the conditions to the inner query and you should get the same results:

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