Which statement correctly describes the difference between TOP and LIMIT clauses in SQL?
Think about which databases you have heard use TOP and which use LIMIT.
TOP is a clause used in SQL Server to limit the number of rows returned. LIMIT is used in MySQL and PostgreSQL for the same purpose. They are not interchangeable across all databases.
Given a table Employees with 5 rows, what will be the output of these two queries?
-- Query 1 (SQL Server): SELECT TOP 3 * FROM Employees ORDER BY EmployeeID; -- Query 2 (MySQL): SELECT * FROM Employees ORDER BY EmployeeID LIMIT 3;
What is true about their outputs?
Consider how TOP and LIMIT work with ORDER BY.
Both TOP 3 and LIMIT 3 limit the output to 3 rows after ordering by EmployeeID. So both return the first 3 rows ordered by EmployeeID.
Which of the following MySQL queries will cause a syntax error?
SELECT * FROM Orders LIMIT;
Check if LIMIT requires a number after it.
LIMIT must be followed by a number specifying how many rows to return. LIMIT; without a number is a syntax error.
In a large SQL Server database, which query is generally more efficient to retrieve the first 10 rows?
A) SELECT TOP 10 * FROM LargeTable ORDER BY CreatedDate DESC; B) SELECT * FROM LargeTable ORDER BY CreatedDate DESC LIMIT 10;
Think about which clause is supported by SQL Server.
SQL Server supports TOP but not LIMIT. Using LIMIT in SQL Server causes syntax error. TOP is optimized for SQL Server.
A developer writes this query in PostgreSQL:
SELECT TOP 5 * FROM Customers ORDER BY CustomerID;
What error will PostgreSQL raise?
Recall which databases support TOP.
PostgreSQL does not support TOP. Using it causes a syntax error near 'TOP'.