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)
 Biggest No

Author  Topic 

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-26 : 02:46:44
Dear All,
I Got Slightly Cofused The Following two Queries. Previously I used the 1st Query to find biggst Number
But My friend said me Don't pass the values to from Caluse, try to pass The Values in Where Clause.
So Finaly I write the 2 Query. But Performace Wise The second Query is Bad.

Please suggest Me


Query 1)Select Min(ColFind) From (Select top 1 ColFind from FindBig Group By ColFind order by ColFind Desc)as a


Query 2)Select Colfind from (
Select colfind from Findbig group by Colfind
) a
Where 1 = (
Select Count(*)+1 from (
Select colfind from Findbig group by Colfind
) b
where a.colfind <b.colfind
)


Thanks
-- KK

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-26 : 02:47:53
Create Table FindBig (ColFind Numeric(8))

Declare @numCnt Numeric(8)
Select @numCnt = 1

While @numCnt< 10
Begin
Insert FindBig Select @numCnt
Select @numCnt = @numCnt+1
End



-- KK
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-26 : 02:55:46
Why can't you use this ?
select max(ColFind) from FindBig



KH

Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-26 : 03:01:25
quote:
Originally posted by khtan

Why can't you use this ?
select max(ColFind) from FindBig



KH





If It's like fifth max means..?
I just put 1 sa example. Exactly i need 30 th maximum

-- kk
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-26 : 03:04:11
here are some reference on this subject
http://sqlteam.com/item.asp?ItemID=16134
http://sqljunkies.com/WebLog/madhivanan/archive/2005/07/26/16222.aspx



KH

Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-26 : 03:12:20
That's fine

Thanks

-- KK
Go to Top of Page
   

- Advertisement -