I have a table that contains a column that acts as a "flag" which is used to decide which table to pull additional information from (i.e. the value 1 pulls from table1, 2 from table2, etc). Usually I would just join the table using indexes/keys. However the table that I could join contained information that could be normalized into separate tables which leaves me to this situation of using a column to decide which table to join.
So here is my question, what is the most efficient way to join different tables based on the value produced in this column?
Here are the two ways I know how to accomplish this task currently. I am pretty sure they are both not the optimal solution:
Pull the information from my main table (containing the column value that decides which table to join), and then through code in my application send additional queries to get the rest of the information.
Go join crazy, return the columns of every table (even if unused). Then, through my code, ignore the nulls of the tables not needed.