Home » SQL & PL/SQL » SQL & PL/SQL » which is faster (10.2.0.4.0)
which is faster [message #383104] Tue, 27 January 2009 04:45 Go to next message
maheshmhs
Messages: 93
Registered: October 2008
Location: Nepal
Member
Hi,

I need distinct values for a column from a table containing millions of rows.

Which of the following could be faster?
Select distinct ColumnName from Tablename 

or
 Select ColumnName from TableName group by ColumnName 

I would appreciate if you would also reply why one is faster than the other.


thank you
Re: which is faster [message #383113 is a reply to message #383104] Tue, 27 January 2009 05:21 Go to previous messageGo to next message
Michel Cadot
Messages: 64109
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
If you want to get distinct use DISTINCT.
If you need to group use GROUP.
The rule is as simple as that.

Regards
Michel
Re: which is faster [message #383114 is a reply to message #383113] Tue, 27 January 2009 05:23 Go to previous messageGo to next message
maheshmhs
Messages: 93
Registered: October 2008
Location: Nepal
Member
thank you Michel,

Since both the queries above result in the same result, I just wanted to know which would be faster. Can anyone suggest me?

[Updated on: Tue, 27 January 2009 06:37]

Report message to a moderator

Re: which is faster [message #383138 is a reply to message #383114] Tue, 27 January 2009 06:42 Go to previous messageGo to next message
dr.s.raghunathan
Messages: 540
Registered: February 2008
Senior Member
generally group by will be called along with another function, anyway since you have millions of rows, you will be the better judge to tell us the time taken after test so that our brain can also enrich on some areas
yours
dr.s.raghunathan
Re: which is faster [message #383142 is a reply to message #383114] Tue, 27 January 2009 06:52 Go to previous message
Michel Cadot
Messages: 64109
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
Can anyone suggest me?

What in the answer I posted is not a suggestion?

You may be able to screw with a hammer, do you think about using it for this?

Regards
Michel
Previous Topic: how to alter columns
Next Topic: How to pass date to the query
Goto Forum:
  


Current Time: Mon Dec 05 09:04:18 CST 2016

Total time taken to generate the page: 0.09475 seconds