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 :: mysql delete rows 
Sql :: get number of columns sql 
Sql :: oracle index size calculation 
Sql :: if column value is null then in mysql 
Sql :: Create boolean column in MySQL with false as default value? 
Sql :: mysql delete data in table 
Sql :: create scalar function in sql server 
Sql :: sql precent format 
Sql :: Index a database column sql 
Sql :: insert into select mysql 
Sql :: SQL Database backup history 
Sql :: q operator in plsql 
Sql :: oracle view dependencies 
Sql :: datediff in sql 
Sql :: mysql get date from datetime 
Sql :: charindex 
Sql :: codeigniter get sql query string 
Sql :: expo sqlite 
Sql :: postgresql default value 
Sql :: mysql locate 
Sql :: mysql disable logging 
Sql :: exec procedure pl sql 
Sql :: sql select inside select 
Sql :: mysql find duplicate rows multiple columns 
Sql :: table structure in sql 
Sql :: mysql timezone 
Sql :: sql where contains part of string 
Sql :: get all employee of salary if more than in sql 
Sql :: delete from table sql 
Sql :: redo files log oracle 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =