Summary

Today you learned how to filter and sort rows from a table in SQL Server. You used the WHERE clause to define search conditions for result sets, and then used the ORDER BY clause to sort those result sets. Finally, you used the DISTINCT keyword to remove unwanted duplicate rows from the results.

Here's the syntax for the SELECT statement so far:

select [distinct] <ColumnName> [, <ColumnName> ...]
from <TableName>
[where <expression> <comparison-operator> <expression>
[and|or <expression> <comparison-operator> <expression> ...]  ] 
[order by <ColumnName> [, <ColumnName> ...]  ]

In conclusion, I leave you with the following list of items:

Do Don't
DO define search criteria in your SELECT statement. DON'T use DISTINCT when it's unnecessary. ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.