Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgresql distinct

SELECT
	DISTINCT bcolor
FROM
	distinct_demo
ORDER BY
	bcolor;
Comment

select distinct 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';
Comment

get distinct elements in table 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)
Comment

PREVIOUS NEXT
Code Example
Sql :: t-sql delete view if exists 
Sql :: sql server rtrim everything after character 
Sql :: t sql null or empty string 
Sql :: sql server output parameter 
Sql :: if else in postgresql 
Sql :: select into temp table 
Sql :: delete row psql 
Sql :: create database sql 
Sql :: create index mysql 
Sql :: sequelize migration default value 
Sql :: mysql ip address 
Sql :: mysql between 
Sql :: import mysql dump command line 
Sql :: mariadb mysql root access denied 
Sql :: how to retrive the today date sql 
Sql :: mysql show schema 
Sql :: laravel general error 2006 mysql server has gone away 
Sql :: sql #region 
Sql :: linq join 
Sql :: how to find the number of rows updated in oracle pl/sql 
Sql :: rename table name 
Sql :: how to check if a column is null in sql 
Sql :: how to lock table in mysql 
Sql :: mysql collation for all languages 
Sql :: soql last week 
Sql :: postgress connection refused 
Sql :: select * where id = 1,2,3 
Sql :: show sql server database 
Sql :: how to import pymysql through jupyter notebook for windows 
Sql :: mysql select count 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =