MySQL SIN() Function
MySQL SIN() Function: Computing Trigonometric Sine Values
The SIN() function returns the sine of an angle given in radians. Its output is a DOUBLE value ranging smoothly between -1 and 1.
In production SQL, SIN() appears frequently inside the Haversine distance formula alongside COS(), ASIN(), and RADIANS(), as well as in seasonal demand curves modeled as smooth sine waves.
Syntax
SIN(x)
x: Numeric angle measured in radians.
Practical Example
Suppose demo_orders models a seasonal sales index by month_num (1 through 12), and you want to compute a smooth cyclical factor using SIN(RADIANS(month_num * 30)).
SELECT
month_num,
ROUND(RADIANS(month_num * 30), 4) AS phase_rad,
ROUND(SIN(RADIANS(month_num * 30)), 4) AS seasonal_wave
FROM (
SELECT 1 AS month_num UNION ALL
SELECT 3 UNION ALL
SELECT 6 UNION ALL
SELECT 9
) AS months;
| month_num | phase_rad | seasonal_wave |
|---|---|---|
| 1 | 0.5236 | 0.5000 |
| 3 | 1.5708 | 1.0000 |
| 6 | 3.1416 | 0.0000 |
| 9 | 4.7124 | -1.0000 |
Month 3 hits 90 degrees (PI() / 2 radians), where SIN() peaks at 1.0000, while month 9 hits 270 degrees (-1.0000).
Common Mistakes & NULL Behavior
- Supplying degrees instead of radians: Calling
SIN(30)computes the sine of30radians (-0.9880), NOT30degrees (0.5). Always convert degrees usingRADIANS(30). - Comparing SIN(PI()) directly to 0: Because
PI()is a finite 64-bitDOUBLEapproximation,SIN(PI())evaluates to1.2246467991473532e-16instead of exact0. Round results withROUND(..., 6)before equality checks. - NULL inputs: Passing
NULLtoSIN(NULL)returnsNULL.
Frequently Asked Questions
What is the valid input range for MySQL SIN()?
SIN() accepts any finite real number without domain errors. Only NULL inputs (or non-numeric errors in strict mode) yield NULL.
How do I write SIN(45 degrees) in MySQL?
Run SELECT SIN(RADIANS(45));, which evaluates to approximately 0.7071067811865475.
What function reverses SIN() back to an angle?
Use ASIN(value) to recover the angle in radians (for inputs between -1 and 1), then wrap it in DEGREES() if you want degrees.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.