i have a table with 3 columns. It is having duplicate on column 2 and 3. I need to select pnly the duplicate rows (with all the 3 columns). How to do that? pls help me.
var1 var2 var3
a a a
b a a
c a a
d b b
e c c
The above is the table structure. It has 3 columsn var1, var2, var3. Based on column var2 and var3 only, we have to assume it is duplicate records. We should not consider var1 while finding the duplicate. Sorry about the alignment.
I have used the below query to get all the rows with / without duplicate but with the rank to identify the duplicate records. But i could not get only the duplicate records.
select var1,var2,var3,ROW_NUMBER() over(PARTITION BY
var2,var3 order by var2,var3) as rnk
from vart
Apart from this, how i can get the maximum rank records amoung the duplicate entries ?
Thanks.
If you want all the rows that have duplicates you can use
count(*) over()Result:
If you want all duplicates but one use
row_number() over()instead.Result: