LMSouq
database Open

Possible to do a MySQL foreign key to one of two possible tables?

AN
Andrew G. Johnson
1 month ago
3 views
Problem Description
Well here's my problem I have three tables; regions, countries, states. Countries can be inside of regions, states can be inside of regions. Regions are the top of the food chain. Now I'm adding a popular_areas table with two columns; region_id and popular_place_id. Is it possible to make popular_place_id be a foreign key to either countries ***OR*** states. I'm probably going to have to add a popular_place_type column to determine whether the id is describing a country or state either way.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base