By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table event(id int);
insert into event(id) values
(1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13);
Records: 13 Duplicates: 0 Warnings: 0
create table event_participation(eventId int, userID varchar(10));
insert into event_participation(eventId, userID) values
(1, 'UserA'), (2, 'UserA'),
(2, 'User1'), (3, 'UserB');
Records: 4 Duplicates: 0 Warnings: 0
SELECT COUNT(DISTINCT e.id) AS count
FROM event e LEFT JOIN event_participation p
ON p.eventId = e.id AND p.userId = 'UserA'
WHERE p.eventId IS NULL
count |
---|
11 |
SELECT COUNT(*) AS count
FROM event e LEFT JOIN event_participation p
ON p.eventId = e.id AND p.userId = 'UserA'
WHERE p.eventId IS NULL
count |
---|
11 |
SELECT COUNT(*) AS count
FROM event e
WHERE NOT EXISTS (
SELECT 1 FROM event_participation p
WHERE p.eventId = e.id AND p.userId = 'UserA'
)
count |
---|
11 |