1. sql
  2. /references
  3. /functions

SQL Functions List

For doing operations on data SQL has many built-in functions.

S. No.CommandDescriptionExample
1ASCII()Returns an ASCII value of the specific characterSELECT ASCII(name) AS CodeOfFirstChar FROM users;
2AVG()Returns the average value of a numeric columnSELECT AVG(price) FROM products;
3COUNT()Returns the number of rows in a table that matches a specified criterionSELECT COUNT(*) FROM customers;
4SUM()Returns the sum of all the values in a numeric columnSELECT SUM(quantity) FROM orders;
5MIN()Returns the smallest value in a columnSELECT MIN(price) FROM products;
6MAX()Returns the largest value in a columnSELECT MAX(price) FROM products;
7UPPER()Converts all the characters in a string to uppercaseSELECT UPPER(name) FROM products;
8LOWER()Converts all the characters in a string to lowercaseSELECT LOWER(name) FROM customers;
9CONCAT()Concatenates two or more strings togetherSELECT CONCAT(first_name, ' ', last_name) FROM employees;
10SUBSTRING()Returns a portion of a string. It takes the form SUBSTRING(string, start, length)SELECT SUBSTRING(name, 1, 3) FROM products;
11LENGTH()Returns the length of a stringSELECT LENGTH(name) FROM products;
12FIRST()Used to return the first value of the columnSELECT FIRST(marks) FROM students
13LAST()This function returns the last value of the columnSELECT LAST(id) FROM orders;
14MID()Extracts substrings in SQL from column values having String data typeSELECT MID(order_id, 3, 5) FROM orders;
15ROUND()Rounds off a numeric value to the nearest integerSELECT ROUND(price, 2) FROM products;
16NOW()This function is used to return the current system date and timeSELECT NOW();
17FORMAT()Used to format how a field must be displayedFORMAT(price, 3)
18CURDATE()Returns the current dateSELECT CURDATE();
19CURTIME()Returns the current timeSELECT CURTIME();
20DATE()Extracts the date part of a date or date/time expressionSELECT name, DATE(birth_time) AS birth_date FROM students;
21EXTRACT()Returns a single part of a date/timeEXTRACT(WEEK FROM "2022-01-17");
22DATE_ADD()Adds a specified time interval to a dateDATE_ADD(users.registration_time, INTERVAL 12 HOUR);

These are just some of the most commonly used SQL functions. There are many more functions available in SQL, depending on the database management system you're using.