Select Query with specific no of rows TOP / ROWNUM / LIMIT

Select query with specific no of rows

Example:

Want to select 4 rows from the table;

Note: you can also used order by with this to find highest salary in table example.

SQL Server

select top 4 column_name from table_name;

Oracle

select columnname from <table_name> where rownum <= 4;

MySQL and PostgreSQL

select columnname from <table_name> limit 4;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.