clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
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. 1579682 fiddles created (21394 in the last week).

select version();
version
PostgreSQL 11.4 (Debian 11.4-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
 hidden batch(es)


CREATE TABLE "locations" ( "code" varchar(10), "location_name" varchar(50) ); INSERT INTO "locations" ("code", "location_name") VALUES ('KL', 'Kuala Lumpur'), ('SG', 'Singapore'), ('JKR', 'Jakarta');
3 rows affected
 hidden batch(es)


CREATE TABLE "payments" ( "location_code" varchar(10), "amount" float8 ); INSERT INTO "payments" ("location_code", "amount") VALUES ('KL', '50'), ('SG', '40'), ('KL', '50');
3 rows affected
 hidden batch(es)


SELECT l.code, SUM(p.amount) FROM locations l LEFT JOIN payments p ON p.location_code = l.code GROUP by l.code
code sum
KL 100
SG 40
JKR
 hidden batch(es)


SELECT l.code, l.location_name, SUM(p.amount) FROM locations l LEFT JOIN payments p ON p.location_code = l.code GROUP by l.code
ERROR: column "l.location_name" must appear in the GROUP BY clause or be used in an aggregate function LINE 3: l.location_name, ^
 hidden batch(es)