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. 2805483 fiddles created (40772 in the last week).

create table parent(parent_id integer not null primary key, name text);
 hidden batch(es)


create table child(child_id integer not null primary key, name text, parent_id integer references parent);
 hidden batch(es)


insert into parent values (1, 'Bill');
1 rows affected
 hidden batch(es)


insert into parent values (2, 'Mary');
1 rows affected
 hidden batch(es)


insert into child values (1, 'Jennifer', 1)
1 rows affected
 hidden batch(es)


select name, exists (select 1 from child where parent_id = p.parent_id) as has_children from parent p;
name has_children
Bill t
Mary f
 hidden batch(es)