I have been taking an online class on relational databases and created an Access database (for the first time) to practice my SQL queries and solve a couple of work-related problems along the way. The database consists of three tables, with the primary table being used to record company wide sales summary information at the branch/store/menu item level (e.g. lowest level of detail) and with three periods of data the database is presently 1.3GB with that one table containing 4,262,421 records.
Everything has gone well until I attempted to run the following query:
SELECT P1.*, P13.[Price?] AS P13Price
FROM (SELECT * FROM PBASE WHERE Period = 13) AS P13, (SELECT * FROM PBASE WHERE Period = 1) AS P1
WHERE P1.Key = P13.Key and P1.[Price?]<>P13.[Price?];
To explain, the big table is PriceAccData and so I first ran a query (PBASE) that added a field to the PriceAccData that I can use as a key to compare price changes from one period to the next (combination of branch, store, menu item). Then I used subqueries to create a data set from the last period of 2013 (Period 13) and the first period of 2014 (Period 1)....from there I attempted to identify items that had changed in price from one period to the next in the Where clause.
I am sure there is a better way to do it, but when I ran the query for only one of the 100 branches it took a while but finished...when I run it for the whole company it locks up Access. My question is two fold 1) is there a more efficient way to run this query which will continue to work quickly as the database grows and 2) the database only contains 3 of 13 periods of data, so I am questioning what should be my long term plan (e.g. what is the most efficient solution to simply store and query data using a desktop).
I'm not a computer science major (I am a CPA with better than average computer skills), so the simpler/clearer the solution and advice the better for me...and thank you in advance for your help.