Get only one repeated value in mysql

2

Well, I have a table and in it a field called cargo and its value can be repeated, for example, the position teacher. In my HTML I'm setting a <select> when I retrieve the value of this field, but due to the value of it being repeated it shows several times the word teacher or any other that repeats in the table, logical. I would like to know if there is any way to "filter" and extract only one value from these repeats?

    
asked by anonymous 12.01.2016 / 14:48

2 answers

0

There are two methods:

1. It would be using DISTINCT

SELECT DISTINCT(cargo) FROM tabela

2. I would be using GROUP BY:

SELECT cargo FROM tabela GROUP BY cargo

Try this clicking here !

Both methods have the same result, as can be seen, there is not much to explain. The function of Group By is to group by equality, summarizing will display one of the duplicates, so it will no longer be a duplication. = D

    
12.01.2016 / 15:07
-1
SELECT cargo FROM 'tabela' GROUP BY 'tabela'.'cargo' ='cargo';

In this way, I force the results where my field is equal to the field that I intend to bring only one result, the ideal is to use normalization as stated above.

    
12.01.2016 / 15:19