![]() ![]() The client wants to generate a list of their employees to generate some statistics. One problem that the distinct keyword does nothing to solve is that sometimes removing duplicates creates misleading results. When are Duplicate Rows Not Duplicate Rows ![]() If only it were always that easy! A quick Internet search on the phrase “sql eliminating duplicates” shows that there’s more to removing duplicate values than inserting the distinct keyword into your SELECT statements. ![]() Now let’s try the query again with the distinct keyword: SELECT DISTINCT nameĪs expected, we now have only one instance of each fruit type: Without the color information, we have multiples of each fruit type: The following query will retrieve all the fruit names from the table and list them in alphabetical order: SELECT name To illustrate how it works, let’s select some data from the following table, which contains a list of fruits and their colors: Distinctrow is an alias for distinct and produces the exact same results: SELECT The distinct keyword comes directly after the SELECT in the query statement and replaces the optional all keyword, which is the default. Did you know that the group by clause can also be used to remove duplicates? If not, read on to find out what the main differences are between them and which to use to produce a desired result. It tells the query engine to remove duplicates to produce a result set in which every row is unique. The go to solution for removing duplicate rows from your result sets is to include the distinct keyword in your select statement. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |