SQlite Querying Across Tables
Created on 2023-08-30T21:00:41-05:00
Question: if all game records share an ID namespace, but records are in separate tables, how do we find which table the ID is used in?
"Union" query will bolt the results of multiple queries together in one result. Make sure you select the fields common to each table (ID, name.)
Within a query you can select from a constant to generate that value. So we generate a constant for each record--equal to the name of the table--which finally gives us the answer of where the ID is used, the name, and which table.
create view id_lookup as select id,name,"table" from (select id, name, 'spells' as "table" from spells union select id, name, 'npc' as "table" from npc);