Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

2 Answers
2

The problem that you are having is most likely coming from the tbl_sales because your item can appear in the table more than once. When you then JOIN your tables together, you are returning the qty from tbl_purchases for each row in tbl_sales.

Simplest solution would be to UNION them. As to error, you are joining sales and purchases, sort of multiplying apples and oranges ( one purchase is multiplied by 3 sales, or vice versa, in first line of your example , rupa 123 - 15 as opposed to 41 - 5 ).