By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Create Table Users(user_id INT, user_name varchar(50));
Insert Into Users Values(11111,'User1'),
(22222,'User2'),
(33333,'User3');
Create Table Messages(message_id VARCHAR(50), content VARCHAR(50));
Insert Into Messages Values
('aaaaa','Hello World'),
('bbbbb','This is a message'),
('ccccc','test test 123');
Create Table object_visited(user_id INT, message_id VARCHAR(50));
Insert Into object_visited Values(11111,'aaaaa'),
(11111,'bbbbb'),
(11111,'ccccc'),
(33333,'aaaaa'),
(33333,'ccccc');
Records: 3 Duplicates: 0 Warnings: 0
Records: 3 Duplicates: 0 Warnings: 0
Records: 5 Duplicates: 0 Warnings: 0
select U.user_id
from Users U left join object_visited O
on U.user_id = O.user_id
left join Messages M
on M.message_id = O.message_id
group by U.user_id
having count(M.message_id) < (select count(message_id) from Messages)
user_id |
---|
22222 |
33333 |