🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to MySQL Notes
Topic #21

MySQL SUM()


MySQL SUM() Function

The SUM() function is used to calculate the total sum of values within a numeric column.

The SUM() function ignores NULL values in the column.

SUM() Syntax

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Demo Database

Below is a selection from the "OrderDetails" table in the Northwind sample database:

OrderDetailID OrderID ProductID Quantity
1 10248 11 12
2 10248 42 10
3 10248 72 5
4 10249 14 9
5 10249 51 40

SUM() Example

The following SQL returns the sum of the Quantity field in the "OrderDetails" table:

Example

SELECT SUM(Quantity)
FROM OrderDetails;

Note: NULL values are ignored.


Add a WHERE Clause

You can add a WHERE clause to specify conditions.

The following SQL returns the sum of the Quantity field for the product with ProductID = 11, in the "OrderDetails" table:

Example

  SELECT SUM(Quantity)
FROM OrderDetails
WHERE ProductId = 11;

Want to go beyond the notes?

Join CodingNow 2.0's MySQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

MySQL SUM() – FAQs

Quick answers about learning MySQL SUM() in MySQL.

This free note from CodingNow 2.0 explains MySQL SUM() in MySQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every MySQL topic on CodingNow 2.0, including MySQL SUM(), is 100% free with no signup required.
With focused practice, most students grasp MySQL SUM() in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now