Hakan Axheim

Hakan Axheim

  • NA
  • 201
  • 32.9k

Regarding performance

Sep 16 2019 1:02 AM
Hi,
 
Back in the old days they said that you should never use select distinct from a database, because the optimizer cannot use index. I want to know if it is some difference in performance between:

select distinct *

with cte as(
   select col1,
               row_number() over (partition by col1 order by col1) as DuplicateCount
   from   table1
select col1 from cte where DuplicateCount = 1;
 
select col1
from   table1
group by col1
 
Maybe it is another way to write an sql statement with best performance regarding select distinct values from on one or more columns.

Answers (1)