Lesson

MySQL SIN() Function

10 min reading
Free Course

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 of 30 radians (-0.9880), NOT 30 degrees (0.5). Always convert degrees using RADIANS(30).
  • Comparing SIN(PI()) directly to 0: Because PI() is a finite 64-bit DOUBLE approximation, SIN(PI()) evaluates to 1.2246467991473532e-16 instead of exact 0. Round results with ROUND(..., 6) before equality checks.
  • NULL inputs: Passing NULL to SIN(NULL) returns NULL.

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.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum