How to select information from a table without duplicate values

Asked

Viewed 74 times

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.

3 answers

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;

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

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