tags:

views:

96

answers:

4

I have a table where each row is a username with associated vote count

The goal is to do paging by username

so you can click on the letter C and get to the C's

But if there are only like 2 C's, then you wanna show 18 D's as well or 12 D's and 6 E's

So how do i find where to start the query like, select from whatever limit XX, 20 how do i find that XX where the C's start, F's start, etc

Basically treat the first letter as a number and select the top 20.

+4  A: 

select * from table where name >= 'C' order by name limit 20

Alex Reitbort
Well, that's almost so easy I'm embarassed
Matt
I think this is way wrong. What about the next page if there are 40 Cs?
DVK
@DVK: you'd save the last one from the previous page and change the > value.
Joel Coehoorn
+3  A: 
SELECT TOP 20 * FROM [Table] WHERE [username] >= 'C' ORDER BY [username]
Joel Coehoorn
+1  A: 

You could always select the top 20.

SELECT Top 20 * FROM Users WHERE Username >= 'C' ORDER BY Username
somacore
+1  A: 

The best way (assuming the pages go to web server and page #N is requested from web server) :

select bottom 20 from 
 ( select top N*20 *
 from   myTable
 order by username
 ) TOPNPAGES
DVK