The goal is to use DISTINCT only on those columns that need to be reduced to a unique subset. This will result in lower sort overhead (shorter records to sort
means less virtual memory and smaller temporary files). We also hope to encourage the Optimizer to use a sorted index to avoid the sort completely.
Applying DISTINCT to a minimal column list could be done using a view or a derived table, as shown in the example below:
select employee_id,
(select last_name
from employee e
where e.employee_id = jh.employee_id)
from
(select distinct employee_id
from job_history
where employee_id < ' 00166') jh (employee_id);