SQLite Forum

request on 5 tables
Login
Where is inner join coming from? That is, why is it relevant?

You have 5 lots of data in 5 tables coming from 5 stores - there is NO link among them.

1. attach each of your databases with an alias 
e.g. 
attach database 'store1.db' as store1;
...
attach database 'store5.db' as store5;

2. put all your data in one table

create temp table allData as 

select 'store1' as source,hours,ID,place1,place2 from store1.yourTable

union all

select 'store2' as source,hours,ID,place1,place2 from store2.yourTable

/* repeat for every table */

union all

select 'store5' as source hours,ID,place1,place2 from store5.yourTable

- now you can use the allData table to group by ID or by ID and source and you will use this to update the table that you hold centrally for your 'bonus' logic.

Your business logic is flawed (i.e. has lots of aspects that are unclear). For instance, how will you avoid double counting? Would you empty each store's table as soon as you've taken a copy? If you do not, you will count this weeks records twice when you repeat your consolidation next week etc. etc. Or you need a marker column to indicate which records are subject to consolidation.