Selecting only non duplicate values from a set of columns

Database
Vga
Enthusiast

Selecting only non duplicate values from a set of columns

Requiement:- I need to remove duplicate from the data set below. The selection criteria for duplicate selection is only the first three columns i.e. C1, C2 & C3.

While selecting the data from source table, the last row should be retained after removing duplicates.

C1|C2|C3|C4|C5|C6

1|2|3|8|9|10

1|2|3|7|8|6

1|2|3|7|8|6

6|4|0|3|5|7

5|2|8|1|3|5

5|2|8|4|9|7

If we consider the above set of data in the same order, expected output can be:

C1|C2|C3|C4|C5|C6

1|2|3|7|8|6

6|4|0|3|5|7

5|2|8|4|9|7

Imp note:- While selecting the source data, no other column should be used in the select statement other than C1/C2/C3 to get the desired output.

Thanks,

VGA

1 REPLY
Enthusiast

Re: Selecting only non duplicate values from a set of columns

try this:

select c1,c2,c3,c4,c5,c6 from your_table qualify row_number() over(partition by c1,c2,c3 order by c6 desc) =1