Home > other >  SQL QUERY to show records of names that are recorded several times and are unique towards each other
SQL QUERY to show records of names that are recorded several times and are unique towards each other

Time:10-03

For example, let us consider this table: In this image consists of rows of 8 where names like Mike,Glenn,Daryl,Shane and Patricia is included with their respective ages

Now I want to insert the type of query that will show the names without repetitions like This, not like This

CodePudding user response:

DISTINCT specifies removal of duplicate rows from the result set.

SELECT DISTINCT Name
FROM tablename

see: use DISTINCT in SELECT

CodePudding user response:

You can use GROUP BY to achieve it.

SELECT * FROM your_table
GROUP BY your_table.name
ORDER BY id

With the data you gave, the result from this query will be:


id name age
1 Mike 25
2 Glenn 19
4 Deryl 56
5 Shane 30
7 Patricia 16
  • Related