i’ve a problem for a table update. follow table structure:
Table1 tableid ... ... productID_1 productID_2 productID_3 Table2 productID Total
I’ve to totalize each product in table2.
For example:
SELECT COUNT(*) as tot, ProductID_1 FROM Table1 GROUP Table1
then the UPDATE table2 SET total =..??? (how can i do) WHERE productID_1 = ….
Hope you can help me.
Thank you
Your options in terms of simplifying the query greatly depend on the product and version you are using. However, a solution that should work in most databases would be:
A big reason this query is cumbersome is that the data in Table1 is not normalized. Instead you should consider a structure for Table1 like: