If the address data was stored as shown below, what is the best way to do a query to check if a user belongs in a particular country? There is a lot of other conditions needed, so I've provided this format for simplicity.
Is doing a union
the most efficient way in this situation?
Tables
User
| id |name|primaryaddrid (FK to Address id)|
|----|----|--------------------------------|
|1 |bill|1 |
UserAddresses
|id|userid|addrid |
|--|------|---------|
|1 |1 |2 |
|2 |1 |3 |
Address
|id|addrline1|country|
|--|---------|-------|
|1 |1 main st|usa |
|2 |1 main st|italy |
|3 |1 main st|peru |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…