add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
select version();
version
PostgreSQL 14.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4), 64-bit
with users (user_id, name) as
( values (1,'user 1')
, (2,'user 2')
, (3,'user 3')
)
, followers ( user_id, other_userid) as
(values (1,2)
, (3,1)
, (1,3)
)
-- your query beging here
select u.user_id
, u.name
, exists(select null
from followers f
where f.user_id = u.user_id
) is_followed
from users u
order by u.user_id;
user_id name is_followed
1 user 1 t
2 user 2 f
3 user 3 t
with users (user_id, name) as
( values (1,'user 1')
, (2,'user 2')
, (3,'user 3')
)
, followers ( user_id, other_userid) as
(values (1,2)
, (3,1)
, (1,3)
)
-- your query beging here
select distinct on (u.user_id) u.user_id
, u.name
, f.user_id is not null is_followed
from users u
left join followers f
on ( f.user_id = u.user_id)
order by u.user_id;
user_id name is_followed
1 user 1 t
2 user 2 f
3 user 3 t