---
title: "How to use sum in MYSQL"  
description: "How to use sum in MYSQL"  
author: "Revati S Misra"  
published: 2023-07-27  
updated: 2023-07-28  
canonical: https://www.mindstick.com/forum/159329/how-to-use-sum-in-mysql  
category: "mysql"  
tags: ["mysql"]  
reading_time: 2 minutes  

---

# How to use sum in MYSQL

How to use [sum](https://www.mindstick.com/forum/159332/how-can-i-use-sum-in-linq) in [MYSQL](https://www.mindstick.com/articles/12156/what-is-mysql)

## Replies

### Reply by Aryan Kumar

The `SUM()` function in MySQL is used to calculate the sum of a set of values. It can be used with any set of numeric values, such as integers, floats, doubles, and decimals.

The syntax for the `SUM()` function is as follows:

SQL

```plaintext
SUM(column_name)
```

The `column_name` parameter is the name of the column that you want to sum. For example, the following SQL statement will calculate the sum of all product prices in the `products` table:

SQL

```plaintext
SELECT SUM(price)
FROM products;
```

This will return a single value, which is the sum of all product prices in the `products` table.

Here is an example of how to use the `SUM()` function in MySQL:

SQL

```plaintext
CREATE TABLE products (
  id INT NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  price INT NOT NULL,
  PRIMARY KEY (id)
);

INSERT INTO products (name, price) VALUES
('Product 1', 100),
('Product 2', 200),
('Product 3', 300),
('Product 4', 400),
('Product 5', 500);

SELECT SUM(price)
FROM products;
```

This will return the following result:

```plaintext
1500
```

As you can see, the `SUM()` function has calculated the sum of all product prices in the `products` table, which is 1500.

Here are some additional things to keep in mind when using the `SUM()` function:

- The `SUM()` function ignores NULL values.
- You can use the `DISTINCT` keyword to calculate the sum of distinct values in a column.
- You can use the `GROUP BY` clause to calculate the sum of values in a group.


---

Original Source: https://www.mindstick.com/forum/159329/how-to-use-sum-in-mysql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
