I have a simple database schema composed of 3 tables
User
id
name
matricule
Document
id
serial
User_Document (join table)
user_id
document_id
I want to check if all items of list( list of Document.serial) exists in the join table(User_Document) then return true If at least one not exists it should return false
There is my current query
SELECT CASE WHEN EXISTS (
SELECT *
FROM user_document ud
INNER JOIN document d ON d.id= ud.document_id
INNER JOIN user u ON u.id = ud.user_id
where u.matricule='123'
and d.serial in ('#1' ,'#2' , '#3')
)
THEN TRUE
ELSE FALSE
END
This doesn't work because it will returns always true even if a single item of list doesn't exist in the join table
I am under PostgreSQL
Thank you very much