Search code examples
mysqlselectfieldvisible

Need a field in SELECT DISTINCT but I do not want it to be printed


I need to have the ID field in the SELECT DISTINCT in order to differentiate 2 cases: duplicates from not duplicates but namesake.

In other words you may have the same person duplicated many times and people with same name and surname in the same db.

If I do not place the ID field in the SELECT, the query returns duplicates and namesakes.

I have to place the ID to eliminate duplicates only. But at the same time, I would like not to print the ID. IS this possible without using the group by ID?

SELECT DISTINCT ID, Name, Surname FROM (SUBQUERY THAT RETURNS DUPLICATES)


Solution

  • Sure:

    Select c.Name, c.Surname 
      From (
        SELECT DISTINCT ID, Name, Surname 
          FROM (SUBQUERY THAT RETURNS DUPLICATES)
      ) as c;