Select Distinct
-
Posted on July 6, 2010 by Derek Dieter
-
0
Select Distinct a way to tell SQL Server to not return duplicate rows. Adding the distinct keyword makes it an expensive query because it essentially performs a group by for all of the returned columns. That being the case, it should only optimally be used on queries that return a small number of rows, or small number of columns.
When using Select Distinct, you should keep in mind that this is generally a workaround to either improper joining of tables, or an improper where clause that is not limiting the result set to only returning one instance of a record.
In order to utilize distinct, all you need to do, is place it before the select list.
[cc lang=”sql”]
SELECT DISTINCT *
FROM yourtable
[/cc]
This will surely only return a unique instance of every record in the result.
- Comments (RSS)
- Trackback
- Permalink