Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

advance quary needed help

Codes here !

Moderators: macek, egami, gesf

advance quary needed help

Postby kick_tisho » Wed Apr 16, 2003 8:51 am

Hi

let's say for simplicity that i have a 'results' table

create table results (
player_id INT
points INT
)

where i log results from a game (user points)

it's easy to make standing stmt which group the players
and order them in desc points order.

select * from results group by player_id order by points desc.

but what if i want to know what's the position of a specific player (for example player_id = 123) with one sql stmt.

now i make a standing stmt and search the results until i found the needed player- it make take about unwanted 3000 compares before i found that he is on 3000-th place.

should i improve my search on php level or there is an sql stmt
that should do the hard work.

if anybody could give me any references, i'll be gratefull.

Stanislav.
kick_tisho
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Nov 22, 2002 7:48 am

Postby Redcircle » Thu Apr 17, 2003 11:28 am

select * from results where player_id = "123" group by player_id order by points desc.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

you don't understand me correctly

Postby kick_tisho » Thu Apr 17, 2003 2:24 pm

i don't need to find the player data, but his position relatively
to the other players with one sql stmt.

for example i need to find the position of player_id = 345.
is it first, second or 99 with one sql stmt.


10x, Stanislav (icq:71729968)
kick_tisho
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Nov 22, 2002 7:48 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.