Today, We want to share with you SQL SELECT SUM on multiple INNER JOIN with another table.In this post we will show you SQL INNER JOIN – Joining Two or More Tables, hear for SUM over distinct rows with multiple joins we will give you demo and example for implement.In this post, we will learn about Using two Sum() functions in a multiple join query with an example.
SQL SELECT SUM on multiple INNER JOIN with another table
There are the Following The simple About SQL Inner Join Multiple Tables with SUM Tutorial Full Information With Example and source code.
As I will cover this Post with live Working example to develop sql sum two columns from two tables, so the sql sum multiple rows with different id is used for this example is following below.
SQL – SELECT SUM joined with another table
There are 2 MySQL Database tables
products(id, product_title, product_desc) transaction(id, qty, product_id)
Now We want to SUM all the quantity based on products, typically what I did is
SELECT product_id, SUM(qty) as total FROM transaction GROUP BY product_id ORDER BY total DESC
But here i am a stuck, We want the product_title and product_desc as well. How to Fetch this in one MySQL query?
Best Solution for Join Query
SELECT id, product_title, product_desc, total FROM products u JOIN ( SELECT product_id, SUM(qty) as total FROM transaction GROUP BY product_id ) AS t ON u.id = t.product_id ORDER BY total DESC
Select sum and inner join
select b.id, b.price, b.paid, sum(t.price) as transactionprice from bills b left join transactions t on t.reference = b.reference group by b.id, b.price, b.paid having b.paid < b.price
I hope you get an idea about mysql sum two columns from two tables.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.