Query Limits, and Distinct and Ordered Data
Explore how to customize SELECT statements in T-SQL by applying query limits with TOP, retrieving unique values using DISTINCT, and organizing output with ORDER BY. Understand how these keywords help control data returned from Microsoft SQL Server tables and improve query results.
We'll cover the following...
We'll cover the following...
In addition to filtering, we can further customize our SELECT statements by using TOP, DISTINCT, and ORDER BY keywords.
Return fixed amount of rows
By default, a SELECT statement returns all rows from the table. If we add filtering options, the statement returns all rows that satisfy the criteria. We can change this behavior by limiting the number of rows returned:
SELECT TOP [MaxNumberOfReturnedRows] * FROM TableSchema.TableName;
...