homepage Welcome to WebmasterWorld Guest from 54.234.217.88
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
select rows over and under specific row
skoff




msg:4480799
 4:14 am on Aug 1, 2012 (gmt 0)

hi guys!

I was wondering something. I have a list of teams with points.
I want to get a specific team and get 2 team over and 2 team under the selected team. These teams are ordered by points.

select * from standing where team=15 order by points desc

so lets say team 15 is ranked 7 then i would like to show teams ranked from 5 to 9.

i dont know if this is all clear but i hope you understand what i mean!

 

coopster




msg:4537770
 9:03 pm on Jan 20, 2013 (gmt 0)

This one slipped through the cracks, did you ever get this query nailed down, skoff?

skoff




msg:4537774
 9:08 pm on Jan 20, 2013 (gmt 0)

No it wasnt it could be nice if you have any idea on what i was asking!

Thanks

jadebox




msg:4539380
 10:00 pm on Jan 25, 2013 (gmt 0)

For MySQL Try:

SELECT (SELECT a.team FROM standing a WHERE a.points < c.points ORDER BY a.Team = 15, a.points DESC LIMIT 1),
(SELECT b.Team FROM standing b WHERE b.points > c.points ORDER BY a.Team = 15, b.points LIMIT 1)
FROM standing c WHERE Team = 15

Basically the above does three queries at once - one to get Team 15's points, one to get the teams (that aren't #15) with less points, and one to get the teams (that aren't #15) with more points.

There are other ways to do it in SQL, but this way seems the easiest to understand.

-- Roger

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved