SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Sql

  1. #1
    SitePoint Member
    Join Date
    May 2004
    Location
    India
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Sql

    How do i limit the number of rows selected,
    like if i want to select the top three sal takers in the emp table.

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2004
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can achieve this by sticking the LIMIT parameter to your SQL statement. This limits the number of results the SQL statement selects from the table(s) to a number you specificy. In your case, you would need to stick LIMIT 3 to your SQL statement.

    In the example you mentioned, where you want to select the top 3 out of the column sal, which is in the table emp, this would result in the following SQL query:

    Code:
    SELECT * from emp ORDER BY sal DESC LIMIT 3;
    Please note that I am assuming that the salaries are noted in the table as integers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •