TOP clause
The TOP clause limits the rows returned in a select result set to a specified number of rows elect single row from a table.
Students table:
ID | NAME | CITY |
---|---|---|
1 | Emma | New York |
2 | Daniel | Chicago |
3 | Joseph | Dallas |
4 | Jennifer | Los Angeles |
5 | Debra | Dallas |
Select single row from a table
select top(1) * from Students;
Results
ID | NAME | CITY |
---|---|---|
1 | Emma | New York |
Select multiple records from a table
select top(2) * from Students order by id desc;
Results
ID | NAME | CITY |
---|---|---|
5 | Debra | Dallas |
4 | Jennifer | Los Angeles |