“Selecione Postgres distintos” Respostas de código

PostgreSql deixou a junção distinta em

Select Distinct On (u.username, u.email)
     u.username
    ,u.email
    ,l.browser
    ,l.login_time
From users u
Join logins l On l.username = u.username
Order By u.username, u.email, login_time Desc
 
                                        ^
Matteoweb

Selecione Postgres distintos

-- NOTE: SELECT DISTINCT ON expressions must match initial ORDER BY expressions


SELECT
   DISTINCT ON (column1) column_alias,
   column2
FROM
   table_name
ORDER BY
   column1,
   column2;
Code language: SQL (Structured Query Language) (sql)

-- EXAMPLE
SELECT
   DISTINCT on (client_id) client_id, id
FROM
   public.dw_client_plan_histories
   where operation = 4
        and original_created_at >= '2022-06-17';
Tiago F2

Obtenha elementos distintos na tabela psql

postgres=#  select distinct on (col1) col1,col2,col3 from test order by col1;

 col1 | col2 |    col3    

------+------+------------

    1 | abc  | 2015-09-10

    2 | xyz  | 2015-09-13

    3 | tcs   | 2015-01-15

(3 rows)
Lively Locust

Respostas semelhantes a “Selecione Postgres distintos”

Perguntas semelhantes a “Selecione Postgres distintos”

Mais respostas relacionadas para “Selecione Postgres distintos” em Sql

Procure respostas de código populares por idioma

Procurar outros idiomas de código