How to select top row value from SQL Table using command?

Asked 14-Sep-2021
Viewed 416 times

0

How to select top row value from SQL Table using command?


1 Answer


0

SQL ‘Select Top’ Statement-
This SQL statement returns the top value in where in want to retrieved.
This is used when there is a large number of data is stored in database table then fetching all data is taking more time then that case we use ‘Select Top’ command to find the specific data from table.
Syntax :
        SELECT TOP Number * | PERCENT column_name(s)
        FROM table_name WHERE condition;
Example : Lets have a table 'Customer'
                        How to select top row value from SQL Table using command?
   
  The following statement returns top 4 row data from table.
                select top 4 * from Customer;
                    How to select top row value from SQL Table using command?
The following statement returns the Top 40 % row data from 'Customer' table.
                select top 40 percent * from Customer;
            How to select top row value from SQL Table using command?

The following statement select top 2 row from table 'Customer' where city = New York.
                select top 2 * from Customer where city='New York';
                How to select top row value from SQL Table using command?