LIMIT Function in SQLThe LIMIT function in Structured Query Language returns the records from the table according to the specified limit value. All the SQL version does not support the LIMIT function. It is important to note that the value of LIMIT must be a non-negative integer. Syntax of LIMIT FunctionIn SQL, we can use the LIMIT function with the columns of the string as well as integers. In this syntax, we have to the specify the LIMIT keyword with its value after the name of the table. Examples of LIMIT functionExample 1: This example uses the LIMIT function with the table in Structured Query Language. The following block shows how to create the new table in Structured Query Language: The following CREATE statement creates the Fresher_Marks table: The below INSERT queries insert the records of freshers with marks and details in the Fresher_Marks table: The following SELECT statement displays the inserted records of the above Fresher_Marks table:
Query 1: The following SELECT query uses the LIMIT keyword to show the first five rows of the above table: Output:
Query 2: The following SELECT query uses the LIMIT keyword in the ORDER BY clause with the DESC query to show the last five percentage: Output:
LIMIT Function with OFFSETThe OFFSET keyword with LIMIT function specify that row from where data is to be shown. The value of OFFSET can never be negative, otherwise it returns error. We can specify the value of OFFSET as zero or greater than zero. Example of LIMIT Function with OFFSETThe following CREATE statement creates the Product_Details table for storing the price and quantity of products: The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table: The following SELECT statement displays the inserted records of the above Product_Details table:
Query 1: The following SELECT query uses the LIMIT function with the OFFSET keyword with the above table:
Next TopicCEILING Function in SQL |