I have a module that generates sales report for me and it has multiple options for filtering the data. The basic query for this is
SELECT DISTINCT o.orders_id from orders o
WHERE o.date_purchased >= '2017-01-01 00:00:00'
AND o.date_purchased < '2017-04-28 00:00:00';
If I wanted to only search for sales within the UK it would add
AND FIND_IN_SET (o.customers_country, 'United Kingdom')
I want to have the ability to filter by custom id so that I can generate a report that only looks at specific products. This id is stored in
products_with_attributes_stock.customid
I've included a list of the tables that contain the data needed to cross reference to collect the customid. See bellow:
I could do several queries and use the result from one to filter the results of the next until I get the customid, but that seems rather clunky.
I think it can be done using INNER JOIN, but to be honest I'm rather confused as to how to join all the tables and matching columns together.
Any help to understand how to achieve this would be appreciated as I need to do more of the same for other filtering options.