Top 10 Query in Different Databases
If you are working with Data, hope you are familiar with different databases. Professionally I have worked with Oracle, MySQL, Microsoft SQL Server, DB2 in different course of time and personally I have worked with some other databases also. There are some common features in different databases but in some cases structures are not same. If you work with database you have to know how to find top ten or top N rows from different scenarios. Today I’ll show you structure of top 10 query in different databases.
Microsoft SQL Server:
SELECT TOP 10 column_names FROM table_name
Oracle:
SELECT column_names FROM table_name WHERE ROWNUM <= 10
IBM DB2:
SELECT column_names FROM table _name FETCH FIRST 10 ROWS ONLY
MySQL:
SELECT column_names FROM table_name LIMIT 10
PostgreSQL:
SELECT column_names FROM table_name LIMIT 10
PostgreSQL v8.3 or later version:
SELECT column_names FROM table_name FETCH FIRST 10 ROWS ONLY
Sybase:
SET rowcount 10 SELECT column_names FROM table_name
You can use above queries to find out top N rows where N is your desired numbers. If are benefited with the above example don’t forget to like our facebook page to get updated.