MySQL - Finding out the count of a product from a transaction table and placing the result into another table

StackOverflow https://stackoverflow.com/questions/23645505

  •  22-07-2023
  •  | 
  •  

Question

I got a question that I need some clarification. Say I have two tables. 1 is a transaction table and another is a product table. The table structure & example looks something like the below. Note Table1 brings in one of the column from Table2 for matching purposes.

Table1

TransactionID,ProductID1,ProductID2,Date

(productID1 and productID2 are the same)

Table2

ProductID2,TransactionCOUNTforthatDay

I want to find out the count/occurence of all/a particular product transaction from table1 (i.e, the amount of transaction say for the 1st of APRIL) and take that result and insert it into the table2 - TransactionCOUNTforthatDay column based on the ProductID.

How can I do this when both the tables aren't identical?

Always getting SQL error. Please advise. Thank you.

Was it helpful?

Solution

INSERT INTO Table2 (product_id,CountTransactionDAYOFMONTH)
SELECT product_id,
       COUNT(product_id) as CountTransactionDAYOFMONTH
FROM Table1
GROUP BY TransactionID,
         product_id,
         DateCreated
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top