reggie reggie - 5 months ago 36
SQL Question

Difference between Top and Limit Keyword in SQL

A quick Question. Suppose I have the following two queries:

SELECT TOP 2 * FROM Persons;


and

SELECT * FROM Persons limit 2;


I want to know the difference between the execution of the above 2 queries?
Basically, I want to know when should I use the
limit
keyword and when it is appropriate to use the
top
keyword.
Also, How does the database return results based on the above 2 queries.

Answer

If you are using SQL Server use TOP if you are using MySQL or Postgres use Limit!

AFAIK there is no product that currently supports both. Here's one list of current implementations and here's another (covers more products but in less detail)

Comments