TOP Operator
The TOP
operator is used to limit the number of rows returned by a query. It is useful for fetching a subset of records.
Example: Using TOP
SELECT TOP 5 Name, City
FROM FreedomFighters
ORDER BY BirthDate DESC;
Output:
Returns the top 5 oldest freedom fighters, sorted by birth date in descending order.
Do's and Don'ts
Do's
- Use
TOP
to fetch a specific number of records efficiently. - Combine with
ORDER BY
for meaningful subsets of data.
Don'ts
- Don't forget to specify the order in which records should be fetched.
- Don't use
TOP
without understanding its impact on data completeness.