Home » SQL & PL/SQL » SQL & PL/SQL » Using Distinct to sort
Using Distinct to sort [message #1115] Tue, 02 April 2002 15:21 Go to next message
Lisa
Messages: 31
Registered: September 2000
Member
Does "distinct" perform a sort? And if so, is it by ascending order? Therefore, if I am using "distinct", I do not need to include "order by".
Example:
Select DISTINCT user from user_table;
Re: Using Distinct to sort [message #1118 is a reply to message #1115] Tue, 02 April 2002 18:03 Go to previous messageGo to next message
fidelia
Messages: 3
Registered: April 2002
Junior Member
Distinct does not automatically sort the column, therefore you still need to use order by clause.
Re: Using Distinct to sort [message #1131 is a reply to message #1118] Wed, 03 April 2002 08:29 Go to previous messageGo to next message
Lisa
Messages: 31
Registered: September 2000
Member
I've been researching and I believe that it does use a sort.

Optimizing Sorts

The following operations require Oracle to perform a sort: Creating an Index, ORDER BY, GROUP BY, DISTINCT, UNION, INTERSECT and MINUS.

Source:
http://www.oraclenotes.com/study_brief/ocp8_SB_performance_tuning.htm
Re: Using Distinct to sort [message #1134 is a reply to message #1115] Wed, 03 April 2002 09:44 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
You always need to include an ORDER BY clause to ensure that your result set is in a particular order.

Although at times it seems you can rely on GROUP BY or DISTINCT to do the "ordering" for you, this is not always the case.
Previous Topic: Primary Key Information
Next Topic: Dynamic SQL and Cursor
Goto Forum:
  


Current Time: Thu Apr 25 21:17:39 CDT 2024