Constraint, based on join with another table

Viewed 1292

I have table tariffs, with two columns: (tariff_id, reception)

I have table users, with two columns: (user_id, reception)

And I have table users_tariffs with two columns: (user_id, tariff_id).

I want to prevent situation when tariff from one reception is assigned to user from another reception. How can I do that?

E.G

Users:

user_id | reception
Putin   | Russia
Trump   | USA

Tariffs:

tariff_id | reception
cheap     | USA
expensive | Russia

Wrong situation at users_tariffs, because Cheap tariff is for USA only:

user_id | tariff_id
Putin   | Cheap
1 Answers
Related