Joining multiple SQL tables with table names in row of table
===

I am using SQLite and I'm not sure if this can be done. Consider I have these table:

Table: Total_Table

_id    Name   Ingredients

0     "A"     "table_a"<br>
1     "B"     "table_b"

Table: table_a

_id    Name

0      "a_1" <br>
1      "a_2"

Table: table_b

_id    Name
0      "a_1" <br>

The tables referenced in the rows of |Total_Table| have a different number of rows and are created as rows in |Total_Table| are added. At the moment, I need to structure a query which will return rows from |Total_Table| but will search through the entries of the |Ingredients| tables. For example, if I am looking for all rows in |Total_Table| which have "a_1" in their |Ingredients| table, it would return rows 0,1 from |Total_Table|.

Currently, I am doing this by querying all rows of |Total_Table|, then iterating through those entries and querying each table individually, forming an array as I go. This is pretty bad since the tables I am looking through are relatively large, and hurts performance.

Any ideas? Thanks!