Can someone help me convert my MySQL querie to SQL?
I can’t use “limit 5” in SQL.

SELECT sum(tid), student.Namn FROM student, mingle WHERE GROUP BY namn ORDER BY sum(tid) DESC limit 5


cj 27-nov-2006 19:25 (in antwoord op 56877)

The preferred solution is to make use of the analytic function ROW_NUMBER. There is a description in the Oracle documentation. The final example shown returns only the fifty-first through one-hundredth row of the EMPLOYEES table:

SELECT last_name FROM 
   (SELECT last_name, ROW_NUMBER() OVER (ORDER BY last_name) R FROM employees)
   WHERE R BETWEEN 51 and 100;
An alternative is to use:
    select * 
      from ( select a.*, rownum rnum
            from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
           where rownum <= MAX_ROWS )
     where rnum >= MIN_ROWS;

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.