SQL SELECT SUM on multiple INNER JOIN with another table

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.

Read Also:  check if folder exists before create directory Laravel

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

Read Also:  sql full join Example

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

Web Programming Tutorials Example with Demo

Read :

Read Also:  CRUD Insert Edit Update Delete Node js with MYSQL

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel 5.7 Get Current Page URL path
  2. Read Also:  SQL LEFT OUTER JOIN overview and examples
  3. Read Also:  Display Live Date Time using JQuery and JavaScript
  4. Read Also:  ASP.NET MVC Web Configuration File web.config
  5. Read Also:  [SOLUTIONS] 500 INTERNAL SERVER ERROR PHP
  6. Read Also:  Jquery Get Number of Characters String length
  7. Read Also:  Vue.JS Automatically Page Redirection
  8. Read Also:  sql subquery example
  9. Read Also:  Laravel Drop hascolumn if exists in Migration
  10. Read Also:  ASP.NET MVC Web Configuration File web.config