INTRODUCTION
A sales dataset containing 10 Excel workbooks were imported to SQL. Different queries were ran.
DATA SOURCE
The data source can be found here
DATA IMPORTATION
A database was created on MS SQL and the files were imported as flat files because the excel workbooks were in csv format.
QUERIES USED
There were 3 'Sales Data' for 3 years (2020 - 2022). I used UNION ALL to combine all three tables into one. I was able to use UNION ALL because all three tables had the same number of columns with the same data type and in the same order. If all three conditions were not met, I would not have been able to use it. I could also use UNION but I wanted the duplicates, if any, to show, and UNION picks just the distinct values i.e. no duplicates. So, I used UNION ALL.
There was no matching parameters connecting all the tables, so, 'INNER JOIN' was used.
There are different types of Joins all performing different tasks, so, you need to know your use case before you can determine the type of join to use.
As seen in the image above, inner join is used to select records that have matching values in both tables. There were times when multiple INNER JOIN functions were used and that was to connect multiple tables to create multiple relationships.
I also had some subqueries inside my main query. The subquery runs before the main query.
FINAL RESULT
The final result can be found here.