1
Let’s say I have a table called ALUNOS
, with 3 columns, ID
, NAME
, SOBRENOME
And I want to take all SURNAMES, but in a way that does not duplicate if a student has the same surname as another student.
1
Let’s say I have a table called ALUNOS
, with 3 columns, ID
, NAME
, SOBRENOME
And I want to take all SURNAMES, but in a way that does not duplicate if a student has the same surname as another student.
1
Just use distinct
SELECT DISTINCT sobrenome FROM alunos;
1
Just use DISTINCT
SELECT DISTINCT SOBRENOME FROM ALUNOS;
Alternatives: Use a
GROUP BY
SELECT SOBRENOME FROM ALUNOS GROUP BY SOBRENOME;
That’s exactly it, thanks!
GROUP BY would be for counting?
No to count would be: SELECT COUNT(*).
Ah thanks! I was trying otherwise.
And to return the count along with the selection would be possible?
0
All you have to do is this:
SELECT DISTINCT (NOME) FROM TABELA;
So only one name will come if there are several equal.
Browser other questions tagged sql
You are not signed in. Login or sign up in order to post.
try to use
DISTINCT
in instructionSELECT
ex:SELECT DISTINCT
SELECT DISTINCT;– Hebert Lima