Search code examples
sqlresultsetsql-limit

How to limit the results on a SQL query


I'm wondering is it possible to limit the result of a SQL request?

For example, only return up to 50 rows from:

  SELECT * FROM <table>

thanks.


Solution

  • Yes, this is possible. This differs between db engines.

    Postgres:

    SELECT * FROM <table> LIMIT 50
    

    SQL Server:

    SELECT TOP 50 * FROM <table>