Ask a question »

SQL - Avoid duplicates in the result of a SELECT query

July 2015


SQL - Avoid duplicates in the result of a SELECT query




Issue


How to avoid duplicates in the results of a SQL query?

Solution

  • Simply use the DISTINCT clause and between the SELECT clause and the fields.
  • Example:
  • SELECT distinct id,name,surname FROM mytable
  • More informations available on this : Link
For unlimited offline reading, you can download this article for free in PDF format:
Sql-avoid-duplicates-in-the-result-of-a-select-query.pdf

See also

MySQL - Evitar los duplicados en un SELECT
By Carlos-vialfa on October 12, 2010
MySQL - Éviter les doublons dans un SELECT
By Jeff on September 4, 2009
SQL - Evitare i doppioni in SELECT
By zig@ on April 2, 2010
MySQL - evitar as duplicatas em um SELECT
By pintuda on March 20, 2012
MySQL- jak unikn?? duplikatów w SELECT?
By technomix on August 20, 2014
Original article published by Jeff. Translated by jak58. - Latest update by deri58
This document entitled « SQL - Avoid duplicates in the result of a SELECT query » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.