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
 SQL Server Development (2000)
 How to select TOP 1?

Author  Topic 

metroix
Starting Member

16 Posts

Posted - 2008-07-11 : 16:19:33
i have a game ranking and i want to make a number 1 player
for that i need to select the first row of my ranking this is the query of the ranking

$query=mysql_query("SELECT * FROM characters where gm = 0 ORDER BY  level DESC, exp DESC LIMIT $start, $upp",$con);

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-11 : 16:32:26
This looks like MySql. You should post your question on a MySql forum such as the one over at dbforums(.com). SQLTeam is for Microsoft SQL Server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-12 : 05:27:16
quote:
Originally posted by metroix

i have a game ranking and i want to make a number 1 player
for that i need to select the first row of my ranking this is the query of the ranking

$query=mysql_query("SELECT * FROM characters where gm = 0 ORDER BY  level DESC, exp DESC LIMIT $start, $upp",$con);



Do you have any problem with that query?
Do you want to convert that to SQL Server specific query?

As said, if you use mysql, then post at mysql forums like www.mysql.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-07-12 : 06:16:35
declare @sql varchar(2000),@ctr int
set @ctr=1
set @sql='select top'+@ctr+' * from tablname'
exec(@sql)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-12 : 06:20:29
quote:
Originally posted by DURGESH

declare @sql varchar(2000),@ctr int
set @ctr=1
set @sql='select top'+@ctr+' * from tablname'
exec(@sql)


Dont use Dynamic sql

declare @sql varchar(2000),@ctr int
set @ctr=1
Set Rowcount @ctr
select * from tablname order by somecol
set rowcount 0


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -