Writing the title is hard, so here's the issue.
store_id | supplier_id | supplier_is_active
A | 2 | 1
A | 3 | 0
B | 4 | 0
B | 5 | 1
I need to make sure that each store_id can only have one active supplier, and I'd like to do this via a table constraint CHECK. But I don't think it's possible to do aggregation within a constraint.
Any thoughts to a clever workaround?