Get a single record for equal columns

0

I have an example table:

produto    |   supermercado
----------------------------
    1      |        1
    4      |        2
    6      |        1
    5      |        1
    8      |        2
    7      |        3

I want to get all the existing supermarkets on this table, without picking up repeated numbers. The result would be:

 supermercado
----------------
      1
      2
      3

Disregarding repeat supermarkets. I could not even begin with a query , because I do not know how to do it to get those results equal.

    
asked by anonymous 11.05.2016 / 19:16

3 answers

2

To get equal results, just use the DISTINCT command in the query.

So it does not return repeated values, it would look like this:

SELECT DISTINCT carrinhos.supermercado FROM carrinhos 
    
11.05.2016 / 19:32
1

Use the word "distinct" in your sql query, it has the exact function of deleting repeated values in the query:

select distinct supermercado from tabela
    
11.05.2016 / 19:31
0

To make the DISTINCT of a single column use DISTINCT ON.

select distinct on (ed.id) ed.id, ed.nome from eventodisparo ed
    
26.04.2018 / 18:14