CHAPTER 6
Advanced Select Techniques
It’s easy to return data from a table. What’s not so easy is to get the data you need how you need it, utilizing fast, set-based methods. This chapter will show you some of the advanced techniques that can be used when selecting data.
6-1. Avoiding Duplicate Results
Problem
You need to see all of the dates where any employee was hired. However, you have hired multiple employees on the same dates, and you want to see the date only once.
Solution #1
Utilize the DISTINCT clause of the SELECT statement to remove duplicate values.
SELECT DISTINCT HireDateFROM HumanResources.EmployeeORDER BY ...
Get SQL Server 2012 T-SQL Recipes: A Problem-Solution Approach 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.