I have two tables Notification and Acknowledgment. Acknowledgment has a field which holds the primary key of Notification table. Basically a Notification will have many Acknowledgments.
Tables: Notification Acknowledgment
fields: id, notifier id, parent_id, status
Now I have to choose rows from Notification such that:
- there is no Acknowledgment WHERE Acknowledment.parent_id = Notification.id (basically no Acknowledgment for that particular Notification)
//or - if there is an Acknowledgment for Notification, then select Notification if any of the Acknowledgments with parent_id = Notification.id has a Acknowledgment.status = someValue
A pseudo SQL code:
"SELECT * FROM Notification (WHERE id is not present in Acknowledgment.parent_id) OR
(WHERE id is present in Acknowledgment.parent_id AND Acknowledgment.status=@someValue"
I can break it into simpler queries and achieve this, but I would love to know one single query to get this done..
1 Answer