air
air

Reputation: 6264

select top 50 records from sql

i have following database table name tbl_rec

             recno   uid   uname   points
             ============================
              1       a     abc      10
              2       b     bac      8
              3       c     cvb      12
              4       d     aty      13
              5       f     cyu      9
              -------------------------
              -------------------------

i have about 5000 records in this table.

i want to select first 50 higher points records.

i can't use limit statement as i am already using limit for paging.

Thanks

Upvotes: 0

Views: 1725

Answers (2)

Your Common Sense
Your Common Sense

Reputation: 157864

I am stupid. Didnt get it right at first.
Pagination itself is displaying top XX!

Want it pagitnated? All right, order table as you wish and make limit whatever you want. Then paginate until it reach 50, then stop.

Upvotes: 1

OMG Ponies
OMG Ponies

Reputation: 332571

i want to select first 50 higher points records.

Then:

  SELECT tr.*
    FROM TBL_REC tr
ORDER BY tr.points DESC
   LIMIT 50

i can't use limit statement as i am already using limit for paging.

Then use a subquery:

SELECT x.*
  FROM (SELECT tr.*
          FROM TBL_REC tr
      ORDER BY tr.points DESC
         LIMIT 50) x
 LIMIT a, b --for your pagation

Upvotes: 4

Related Questions