“Seleccione Distintos Postgres” Código de respuesta

PostgreSQL Izquierda se une distinta en

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

Seleccione Distintos Postgres

-- 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

Obtenga elementos distintos en la tabla 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

Respuestas similares a “Seleccione Distintos Postgres”

Preguntas similares a “Seleccione Distintos Postgres”

Más respuestas relacionadas con “Seleccione Distintos Postgres” en Sql

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código