SELECT
The SELECT statement retrieves rows from one or more tables or views.
SELECT [TOP (expression)] [ALL | DISTINCT]
column_list
FROM table_expression
[WHERE search_condition]
[GROUP BY grouping_column_list]
[HAVING search_condition]
[ORDER BY order_by_expression [ASC | DESC]];
| Clause | Description |
|---|---|
TOP | Limits the number of rows returned. |
DISTINCT | Removes duplicate rows. |
WHERE | Filters rows based on a condition. |
GROUP BY | Aggregates rows sharing a property. |
HAVING | Filters groups after aggregation. |
ORDER BY | Specifies the sort order of the result set. |
Example:
SELECT TOP 10 FirstName, LastName, Email FROM dbo.Users WHERE IsActive = 1 ORDER BY CreatedDate DESC;