SQL Recipes (Beta II)
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
  #1 (permalink)  
Old 09-01-2006, 11:52 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default MySQL dialect question:

How do I select the highest 20 to 30 values?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 09-02-2006, 12:00 AM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default MySQL answer. Re: How do I select the highest 20 to 30 values?

The idea is always the same and can be adjusted to select any position. First you have to order the query and select the first 19 values (Let's say we want the 20th to 30th highest score in a competition). Then exclude the first 19 rows, and return the next 10 rows. This will give you the 20th to 30th highest score.

SELECT * FROM competition WHERE id NOT IN (SELECT id FROM competition ORDER BY score DESC LIMIT 19) ORDER BY score DESC LIMIT 10
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-02-2006, 07:50 AM
Dimitar
 
Posts: n/a
Default MySQL answer. Re: How do I select the highest 20 to 30 values?

Wouldn't this also do the trick?
SELECT * FROM competition ORDER BY score DESC LIMIT 19,10;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
  #4 (permalink)  
Old 09-03-2006, 06:05 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default MySQL answer. Re: How do I select the highest 20 to 30 values?

Dimitar, Good point :-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-18-2008, 10:56 AM
Unregistered
 
Posts: n/a
Default ANY answer. Re: How do I select the highest 20 to 30 values?

SELECT TOP (10) ShippingId
FROM Shipping
WHERE (ShippingId NOT IN
(SELECT TOP (20) ShippingId
FROM Shipping AS Shipping_1
ORDER BY ShippingId DESC))
ORDER BY ShippingId DESC
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to select highest value and then create new object with that value +1? Pureke SQL - Questions and Answers 2 01-23-2007 03:30 AM


All times are GMT. The time now is 07:37 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2007 SQL Recipes

1 2 3 4 5 6 7