Hello
I am trying to compile a query but getting inconsistent data from it. I need to make use of two tables namely:
transaction_pro ducts [contains products related to a transaction in transactions table]
refunds [contains refunded product details related to a transaction in transactions table]
Both of the above tables contain product_id and I would like to join the tables to gather some detailed information about sales. I know it sounds like a simple job but I keep getting inconsistent results from the join, here is the sample query I am using to join:
SELECT transaction_pro ducts.id, sum(transaction _products.qty), sum(refunds.pri ce) FROM refunds NATURAL JOIN transaction_pro ducts GROUP BY transaction_pro ducts.id;
Now when I run a group by query on a single table I get the sum calculated fine, however after doing a join like the above I get the amounts to be higher than their original sum in all the products for both the qty and the price. I am not sure where I am going wrong with this, could someone pleas e shed some light on this problem and put me in the right direction.
Thanks
I am trying to compile a query but getting inconsistent data from it. I need to make use of two tables namely:
transaction_pro ducts [contains products related to a transaction in transactions table]
refunds [contains refunded product details related to a transaction in transactions table]
Both of the above tables contain product_id and I would like to join the tables to gather some detailed information about sales. I know it sounds like a simple job but I keep getting inconsistent results from the join, here is the sample query I am using to join:
SELECT transaction_pro ducts.id, sum(transaction _products.qty), sum(refunds.pri ce) FROM refunds NATURAL JOIN transaction_pro ducts GROUP BY transaction_pro ducts.id;
Now when I run a group by query on a single table I get the sum calculated fine, however after doing a join like the above I get the amounts to be higher than their original sum in all the products for both the qty and the price. I am not sure where I am going wrong with this, could someone pleas e shed some light on this problem and put me in the right direction.
Thanks
Comment