select unique name in mysql table

Asked

Viewed 294 times

1

Well, I have a constant doubt when selecting something in mysql, I have a mysql table that contains a column called Name in it contains the following values

|name |Aline |Alice |Aline |Valdemord |Aline

and another column called ID in it containing

1|1|2|2|3|3|3|

good in them the doubt is the following, as I would select for example, search in them the unique names and print each name only once, however if you have 2 Aline, show only one Aline, and in the case of the values of this second table of ids, show something from the team all id 1 is from TIME 1 all id is from the RED team.

  • tried to use distinct? SELECT DISTINCT nome FROM Tabela

1 answer

0

You have 2 options, you can use Group by and Distinct
Example with group by:

select id, nome from  tabela
    where ....
    group by nome

Example with the distinct:

select DISTINCT nome, id from  tabela
    where ....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.