I have two tables Card
and History
with a one-to-many relationship: one card can have one or many histories. Card
has a CardId
column, and History
has a CardId
and a StatusId
column.
I want a SQL script which selects the only cards which have no one history with StatusId=310.
This is what I've tried.
SELECT
C.CardId
FROM
Card C
WHERE NOT EXISTS (SELECT *
FROM History H
WHERE H.CardId = C.CardId AND H.StatusId = 310)
But I want to know if there is an efficient way.
Thanks in advance.