Saturday, March 29, 2008

SQL..Problems with Distinct ON

The DISTINCT ON clause is not part of the SQL standard &
its result is not always determinate.
So although it is often the most obvious alternative & convenient also, think twice before using it.
Ask yourself:
1. Do I want sql written by me to be portable to sometoher DBMS?
2. Do I want to avoid indeterminate nature of result?

If any of the above question is NO, then try to use GROUP BY and subqueries in FROM to implement the same thing and avoid Distinct ON.

No comments: