Roger Andersson wrote: > > I have multiple databases, both have a table called "lists" inside this > table is the names of other tables in the database that make up the lists. > Each individual list is made up of the tables that have the same name in > each database (the list is split between different storage devices in this > case). > e.g. > > database 1 > "lists" list_1, list_2 > "list_1" item_1, item_2 > "list_2" item_1, item_2 > > database 2 > "lists" list_1, list_3 > "list_1" item_3, item_4 > "list_3" item_1,item_2 > > To get an output with all the lists of both databases i can use a union > command on the "lists" table: > > select * from database1.lists union select * from database2.lists; > > However if i'm not sure which approach to take to get the contents of a > specific list. I'm trying to replicate this sort of statement: > > select * from database1.list_2 union all select * from database2.list_2; > > but by my scheme you can't be sure if the list_1 table exists in database2, > which if i'm right will error the statement and provide no output? > The other option is to run a set of statements first checking whether the > table exists and keeping a record of which database does and building the > statement that way, but this seems inelegant. I was hoping someone would > have seen this kind of behaviour before and could point me in the right > direction of a solution? All comments are welcome. > > _______________________________________________ > Maybe something like > > select db1.* from database1.lists db1 union select db2.* from > database2.lists db2; > and > select db1.* from database1.list_2 db1 union all select db2.* from > database2.list_2 db2; > > /Roger > Thanks for the suggestion, but for the second statement as list_2 does not exist in database2 wouldn't this statement fail with a compile error rather than give an output?
Andrew _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users