SyntaxStudy
Sign Up
MySQL Introduction to SQL Functions
MySQL Beginner 5 min read

Introduction to SQL Functions

SQL functions are built-in routines that perform operations on data and return a result. MySQL provides a rich library of functions covering string manipulation, numeric calculations, date handling, aggregation, and more.

Categories of MySQL Functions

  • String functions: CONCAT, UPPER, LOWER, SUBSTRING, TRIM, LENGTH, REPLACE
  • Numeric functions: ROUND, CEIL, FLOOR, ABS, MOD, POWER, SQRT
  • Date functions: NOW, CURDATE, DATE_FORMAT, DATEDIFF, DATE_ADD, YEAR, MONTH
  • Aggregate functions: COUNT, SUM, AVG, MIN, MAX
  • Control flow: IF, IFNULL, COALESCE, CASE

Why Use Functions?

Functions let you transform and compute data directly in SQL without fetching raw values into application code. This reduces data transfer, simplifies queries, and keeps business logic close to the data.

Functions can appear in SELECT lists, WHERE clauses, ORDER BY clauses, and even in other function calls (nesting).

Example
SELECT
    UPPER(first_name) AS name_upper,
    LENGTH(email) AS email_length,
    ROUND(salary, 2) AS rounded_salary,
    NOW() AS current_time
FROM employees;
Pro Tip

Functions can be nested: SELECT UPPER(TRIM(name)) removes spaces and uppercases in one step.