STDDEV() measures the population standard deviation of a set of numeric values. STDDEV_POP() and STD() are equivalent in MySQL.
Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.
SELECT ROUND(STDDEV_POP(v), 2) AS population_stddev FROM (SELECT 2 AS v UNION ALL SELECT 4 UNION ALL SELECT 6) AS sample;| population_stddev |
|---|
| 1.63 |
STDDEV() returns the population standard deviation of non-NULL values. STD() and STDDEV_POP() are synonyms for the same population calculation.
The examples use the student table SQL dump.
SELECT STDDEV(mark), STD(mark), STDDEV_POP(mark)
FROM student;
| STDDEV(mark) | STD(mark) | STDDEV_POP(mark) |
|---|---|---|
| 16.49766163752223 | 16.49766163752223 | 16.49766163752223 |
Use FORMAT() when you want a formatted string with a fixed number of decimal places.
SELECT FORMAT(STDDEV(mark), 2)
FROM student;
| FORMAT(STDDEV(mark), 2) |
|---|
| 16.50 |
Use STDDEV_SAMP() when the values are a sample rather than an entire population. Aggregate functions ignore NULL values.
Is STDDEV() the sample standard deviation?
No. In MySQL STDDEV() is a synonym for population standard deviation; use STDDEV_SAMP() for a sample.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.