I have received a SQL query that makes use of the distinct keyword. When I tried running the query it took at least a minute to join two tables with hundreds of thousands of
Yes, as using DISTINCT
will (sometimes according to a comment) cause results to be ordered. Sorting hundreds of records takes time.
Try GROUP BY
all your columns, it can sometimes lead the query optimiser to choose a more efficient algorithm (at least with Oracle I noticed significant performance gain).