LIMIT
Example
Section titled “Example”SELECT * FROM employeesLIMIT 5;Output
Section titled “Output”+-----------+--------+----------+| EmployeeID | Name | Position |+-----------+--------+----------+| 1 | John | Analyst || 2 | Sarah | Designer || 3 | Jane | Developer|| 4 | Bob | Analyst || 5 | Alice | Designer |+-----------+--------+----------+Explanation
Section titled “Explanation”The LIMIT keyword in MySQL is used to specify the maximum number of records to return. In this example, the query is selecting all columns from the “employees” table, but only returns the first 5 records.
Example
Section titled “Example”SELECT * FROM EmployeesLIMIT 5;Output
Section titled “Output”| EmployeeID | LastName | FirstName ||------------|----------|-----------|| 1 | Brown | Julia || 2 | Davis | John || 3 | Miller | James || 4 | Wilson | Patricia || 5 | Moore | Linda |Explanation
Section titled “Explanation”In this SQL query, the LIMIT clause is used to constrain the number of rows returned by the query. This specific query will only return the top 5 records from the ‘Employees’ table.
Example
Section titled “Example”SELECT * FROM CustomersORDER BY CustomerNameLIMIT 3;Output
Section titled “Output”CustomerName | ContactName | Country-------------|-------------|---------Alfreds | Maria | GermanyAnas | Ana | MexicoAround | Thomas | UKExplanation
Section titled “Explanation”Here, the LIMIT clause restricts the output to only the first three records of the Customers table sorted by the ‘CustomerName’ in ascending order.