Tuesday, February 21, 2012

Please don't abuse DISTINCT.

Usually the analyst provide the specification book to me develop the report. Of course the analyst has the idea what to expect on the outcome along with the filters specified. However, when it comes to analyst has no idea what they should be expecting and if they found duplicate in the report, what they'll advise is to applied DISTINCT.

I could understand that applying DISTINCT is the fastest way to solve the problem but it will increase the database execution cost. The solution might have hidden in one of the unique field or certain combination of filters applied but will take much effort to discover, especially for complex SQL.

Well, let see how far DISTINCT could help us until one day it might finally gives up.