T-SQL Tutorial

Select records from table T-SQL


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:

IDNAMECITY
1EmmaNew York
2DanielChicago
3JosephDallas
4JenniferLos Angeles
5DebraDallas

Select single row from a table

select top(1) * from Students;

Results

IDNAMECITY
1EmmaNew York

Select multiple records from a table

select top(2) * from Students order by id desc;

Results

IDNAMECITY
5DebraDallas
4JenniferLos Angeles