SQL Functions List
For doing operations on data SQL has many built-in functions.
S. No. | Command | Description | Example |
---|---|---|---|
1 | ASCII() | Returns an ASCII value of the specific character | SELECT ASCII(name) AS CodeOfFirstChar FROM users; |
2 | AVG() | Returns the average value of a numeric column | SELECT AVG(price) FROM products; |
3 | COUNT() | Returns the number of rows in a table that matches a specified criterion | SELECT COUNT(*) FROM customers; |
4 | SUM() | Returns the sum of all the values in a numeric column | SELECT SUM(quantity) FROM orders; |
5 | MIN() | Returns the smallest value in a column | SELECT MIN(price) FROM products; |
6 | MAX() | Returns the largest value in a column | SELECT MAX(price) FROM products; |
7 | UPPER() | Converts all the characters in a string to uppercase | SELECT UPPER(name) FROM products; |
8 | LOWER() | Converts all the characters in a string to lowercase | SELECT LOWER(name) FROM customers; |
9 | CONCAT() | Concatenates two or more strings together | SELECT CONCAT(first_name, ' ', last_name) FROM employees; |
10 | SUBSTRING() | Returns a portion of a string. It takes the form SUBSTRING(string, start, length) | SELECT SUBSTRING(name, 1, 3) FROM products; |
11 | LENGTH() | Returns the length of a string | SELECT LENGTH(name) FROM products; |
12 | FIRST() | Used to return the first value of the column | SELECT FIRST(marks) FROM students |
13 | LAST() | This function returns the last value of the column | SELECT LAST(id) FROM orders; |
14 | MID() | Extracts substrings in SQL from column values having String data type | SELECT MID(order_id, 3, 5) FROM orders; |
15 | ROUND() | Rounds off a numeric value to the nearest integer | SELECT ROUND(price, 2) FROM products; |
16 | NOW() | This function is used to return the current system date and time | SELECT NOW(); |
17 | FORMAT() | Used to format how a field must be displayed | FORMAT(price, 3) |
18 | CURDATE() | Returns the current date | SELECT CURDATE(); |
19 | CURTIME() | Returns the current time | SELECT CURTIME(); |
20 | DATE() | Extracts the date part of a date or date/time expression | SELECT name, DATE(birth_time) AS birth_date FROM students; |
21 | EXTRACT() | Returns a single part of a date/time | EXTRACT(WEEK FROM "2022-01-17"); |
22 | DATE_ADD() | Adds a specified time interval to a date | DATE_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.