TAN()

SQL · Math Functions

Theory

TAN returns the tangent of an angle, which equals SIN divided by COS. In a right-angled triangle, it is the opposite side divided by the adjacent side, so it describes a slope: rise over run. TAN(0) is 0, the tangent of 45 degrees is 1 (a slope that rises one metre per metre) and the tangent of 60 degrees is about 1.7321.

Like the other trigonometric functions it takes radians, so use RADIANS(). Unlike SIN and COS, TAN is not limited to -1..1: it grows without limit as the angle approaches 90 degrees, where it is undefined (COS is zero there). In floating point you get a huge number instead of an error, so guard angles near 90. A typical use is turning an angle into a height: a ramp that rises at 30 degrees over a 10-metre run gains 10 × TAN(30°) ≈ 5.77 metres. The inverse, ATAN (and ATAN2 for coordinates), turns a slope back into an angle and is available in the same databases.

Why we use it

Slopes, gradients and heights from angles are naturally expressed as a tangent. TAN converts an angle into rise per unit of run, which is what height and gradient calculations need.

When to use it

Use TAN for slope and height-from-angle calculations in engineering or geospatial data. Use ATAN or ATAN2 for the reverse (angle from rise and run). Avoid angles at or near 90 degrees.

How it works

  1. Angle in degrees, e.g. 30
  2. Convert with RADIANS(30)
  3. Angle is 90 degrees (odd multiple)? Yes: Undefined: huge number or error. No: Compute SIN / COS.
  4. Return the slope (0.5774)

Syntax

TAN(radians)

Example

SELECT TAN(0);
-- 0

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic