Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 max in select statement

Author  Topic 

stikiflem1
Starting Member

6 Posts

Posted - 2005-02-09 : 21:31:55
does anybody has an article here about the effects on using MAX in queries? is it that efficient? is there an alternatives aside from using MAX to get the maximum?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-02-09 : 22:23:23
You can also try:

SELECT TOP 1 myColumn FROM myTable ORDER BY myColumn DESC

...instead of:

SELECT Max(myColumn) FROM myTable

But it's unlikely to make much difference. At best it will be just as fast as MAX() would be. However, from a logical standpoint MAX() makes more sense, and uses standard SQL functions and syntax. TOP is not supported by all SQL products.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-02-09 : 22:34:56
Be cautious about max and min in the same statement.

select @max = max(fld), @min = min(fld) from tbl
can be a lot slower than
select @max = max(fld) from tbl
select @min = min(fld) from tbl



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -