In SQL Server, TOP may be used to return the first n number of rows in a query. For example,
SELECT TOP 100 * FROM users ORDER BY idmight be used to return the first 100 people that registered for a site. (This is not necessarily the best way, I am just using it as an example).
My question is - What is the equivalent to TOP in other databases, such as Oracle, MySQL, PostgreSQL, etc? If there is not an equivalent keyword, what workarounds can you recommend to achieve the same result?
This is standard SQL (Oracle and SQL Server implement it). This is an example of returning up to 100 rows:
In DB2 you would make your query look like this:
SELECT * FROM tblData FETCH FIRST 10 ROWS ONLY;
In Oracle you want to use a TOP-N query.
For example:
This will get you the top three results (because I order by desc in the sub query)