What is the proper syntax of the keyword LIMIT to display 5 results after starting at record 4?
Explanation
The SQL SELECT LIMIT statement is used to retrieve records from one or more tables in a database and limit the number of records returned based on a limit value.
LIMIT keyword has the following syntax:
SELECT ...
FROM ...
WHERE ...
LIMIT [offset_value,] number_of_records
where offset_value:
- indicates which record to start from
- is optional and may be skipped

and number_of_records value indicates how many records to return in a result set.
Theory
  • The SQL TOP clause is used to fetch a TOP N number or X percent records from a table.
    Note: All the databases do not support TOP clause. For example MySQL supports LIMIT clause to fetch limited number of records and Oracle uses ROWNUM to fetch limited number of records.

    Syntax:

    The basic syntax of TOP clause with SELECT statement would be as follows:
    SELECT TOP number|percent column_name(s)
    FROM table_name
    WHERE [condition]
    
    Read more: SQL - TOP, LIMIT or ROWNUM Clause
  • Example:

    Consider the CUSTOMERS table having the following records:
    
    | ID | NAME     | AGE | ADDRESS   | SALARY   |
    +----+----------+-----+-----------+----------+
    |  1 | Ramesh   |  32 | Ahmedabad |  2000.00 |
    |  2 | Khilan   |  25 | Delhi     |  1500.00 |
    |  3 | kaushik  |  23 | Kota      |  2000.00 |
    |  4 | Chaitali |  25 | Mumbai    |  6500.00 |
    
    Following is an example on MySQL server, which would fetch top 3 records from CUSTOMERS table:
    
    SQL> SELECT * FROM CUSTOMERS
    LIMIT 3;
    
    This would produce the following result:
    
    | ID | NAME    | AGE | ADDRESS   | SALARY  |
    +----+---------+-----+-----------+---------+
    |  1 | Ramesh  |  32 | Ahmedabad | 2000.00 |
    |  2 | Khilan  |  25 | Delhi     | 1500.00 |
    |  3 | kaushik |  23 | Kota      | 2000.00 |
    
    Read more: SQL - TOP, LIMIT or ROWNUM Clause

Updated. Thanks, @pomanitz

2016 Aug 31, 3:39:29 PM

LIMIT is not SQL. It's using for MySQL... In SQL u can limit rows like this: SELECT TOP 3 * FROM product;

2016 Jul 4, 10:30:56 AM

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по SQL
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты