skip to Main Content

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

Id Name Age
1 Mike 25
2 Glenn 19
3 Glenn 19
4 Daryl 56
5 Shane 30
6 Shane 30
7 Patricia 16

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

EDIT: I entered the data from first picture. The request is to list the names without duplicates, as shown in the second and third picture but I will not convert them to text.

2

Answers


  1. 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
    Login or Signup to reply.
  2. DISTINCT specifies removal of duplicate rows from the result set.

    SELECT DISTINCT Name
    FROM tablename
    

    see: use DISTINCT in SELECT

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search