So I have an address table that is shared among various other tables, such as schools, parks, churches, etc. Schools, parks, etc all foreign key to a row in address.
What I’m wondering is, if I have a specific row in the address table, is there a way to find out which row in which table points to it. So basically just this:
SELECT * FROM schools WHERE address_id = 1
But that would mean I would have to know that the address in row 1 is connected to a school. But what if I don’t know that? It could be 1 of 10 other tables…
You’re going to have to query each of the other tables.
I would do it as a UNION query:
so that you only have to run one query and get back the results as a single dataset that you work with.
If you have a list of tables (or a table of tables), you could generate the query programmaticly — that would save you having to update your query when the tables are changed.