Hakan Axheim

Hakan Axheim

  • 1.8k
  • 115
  • 6.7k

Regarding performance

Sep 16 2019 1:02 AM
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.

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (1)