clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2805496 fiddles created (40755 in the last week).

select version();
version
PostgreSQL 12.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4), 64-bit
 hidden batch(es)


CREATE TABLE tab ( col_A TEXT, col_B TEXT, col_C TEXT );
 hidden batch(es)


INSERT INTO tab (col_A, col_B, col_C) VALUES ('A1', 'B1', null), ('A2', 'B2', null), ('A3', 'B3', null), ('A4', null, 'C1'), ('A5', null, null);
5 rows affected
 hidden batch(es)


SELECT * FROM tab ORDER BY col_A, col_B;
col_a col_b col_c
A1 B1
A2 B2
A3 B3
A4 C1
A5
 hidden batch(es)


WITH x AS (SELECT MAX(col_A) AS a FROM tab), y AS (SELECT MAX(col_B) AS b FROM tab), z AS (SELECT MAX(col_C) AS c FROM tab) SELECT x.a, y.b, z.c FROM x, y, z;
a b c
A5 B3 C1
 hidden batch(es)


WITH x AS (SELECT COALESCE(MAX(col_A), '--') AS a FROM tab), y AS (SELECT COALESCE(MAX(col_B), '--') AS b FROM tab), z AS (SELECT COALESCE(MAX(col_C), '--') AS c FROM tab) SELECT x.a, y.b, z.c FROM x, y, z;
a b c
A5 B3 C1
 hidden batch(es)