Which syntax limits the number of rows to 10 in PostgreSQL/MySQL?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

Which syntax limits the number of rows to 10 in PostgreSQL/MySQL?

Explanation:
Limiting the number of rows returned by a query is done with a LIMIT clause. In both PostgreSQL and MySQL, using LIMIT 10 will return at most 10 rows (you can pair it with OFFSET to skip some rows, e.g., LIMIT 10 OFFSET 20). This is the most portable and common way to restrict results in these two systems. The other options aren’t standard for these databases: TOP 10 comes from SQL Server, not PostgreSQL or MySQL; ROWS 10 isn’t valid on its own and isn’t the typical way to limit results in these engines; and although FETCH FIRST 10 ROWS ONLY is valid ANSI SQL and can be used in PostgreSQL with an ORDER BY, it isn’t supported by MySQL.

Limiting the number of rows returned by a query is done with a LIMIT clause. In both PostgreSQL and MySQL, using LIMIT 10 will return at most 10 rows (you can pair it with OFFSET to skip some rows, e.g., LIMIT 10 OFFSET 20).

This is the most portable and common way to restrict results in these two systems. The other options aren’t standard for these databases: TOP 10 comes from SQL Server, not PostgreSQL or MySQL; ROWS 10 isn’t valid on its own and isn’t the typical way to limit results in these engines; and although FETCH FIRST 10 ROWS ONLY is valid ANSI SQL and can be used in PostgreSQL with an ORDER BY, it isn’t supported by MySQL.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy