SQL SELECT TOP
The SELECT TOP
statement is used to retrieve a specific number of rows from a table. It is useful when you want to limit the number of records returned by a query.
Syntax
The basic syntax for SELECT TOP is:
SELECT TOP n column_name
FROM table_name;
Example
In this example, we retrieve the top 3 products ordered by the most customers.
Code Example
-- Select the top 3 products ordered
SELECT TOP 3 Product FROM Orders;
Output
Laptop
Phone
Tablet
Explanation
- The query retrieves the first three products in the Orders table.
- Use TOP n to specify the number of rows you want to return from the result set.