I am building an Ecommerce system using php mySql, and I don't know how to LEFT JOIN three tables.
I need a list from all store items adding how many views and sales each item has
TABLE #1 - store_sales
---------------
itemID | date
--------------
TABLE #2 - store_views
--------------
itemID | date
--------------
TABLE #3 - store_items
---------------------------------
itemID | itemName
---------------------------------
RESULT
-----------------------
itemID | itemName | COUNT(store_sales) | COUNT(store_views)
EXAMPLE:
-----------------------
itemID | itemName | COUNT(store_sales) | COUNT(store_views)
1 PHONE 3 45
2 BOOK 5 61
MY CODE WITH ERROR:
SELECT
a.itemID ,
b.itemID ,
c.itemID ,
COUNT(if(a.itemID = c.itemID , a.itemID , NULL)) AS views ,
COUNT(if(b.itemID = c.itemID , b.itemID , NULL)) AS sales
FROM store_views a
LEFT JOIN store_sales b
ON a.itemID = b.itemID
LEFT JOIN store_items c
ON a.itemID = c.itemID
WHERE 1=1
GROUP BY itemID