Functions
String Functions
CONCAT - Concatenate strings
SELECT CONCAT(first_name, ' ', last_name) FROM users;LENGTH - String length
SELECT LENGTH(column_name) FROM $TABEL_NAME;UPPER - Convert to uppercase
SELECT UPPER(column_name) FROM $TABEL_NAME;LOWER - Convert to lowercase
SELECT LOWER(column_name) FROM $TABEL_NAME;SUBSTRING - Extract substring
SELECT SUBSTRING(column_name, start_position, length) FROM $TABEL_NAME;LEFT - Extract left characters
SELECT LEFT(column_name, number_of_chars) FROM $TABEL_NAME;RIGHT - Extract right characters
SELECT RIGHT(column_name, number_of_chars) FROM $TABEL_NAME;TRIM - Remove leading/trailing spaces
SELECT TRIM(column_name) FROM $TABEL_NAME;LTRIM - Remove leading spaces
RTRIM - Remove trailing spaces
REPLACE - Replace substring
LOCATE - Find position of substring
REVERSE - Reverse string
REPEAT - Repeat string
LPAD - Left pad string
RPAD - Right pad string
Numeric Functions
ABS - Absolute value
ROUND - Round to decimal places
CEIL/CEILING - Round up
FLOOR - Round down
MOD - Modulo operation
POWER/POW - Power function
SQRT - Square root
RAND - Random number
GREATEST - Maximum value
LEAST - Minimum value
TRUNCATE - Truncate decimal
SIGN - Sign of number
Date/Time Functions
NOW - Current date and time
CURDATE - Current date
CURTIME - Current time
DATE - Extract date part
TIME - Extract time part
YEAR - Extract year
MONTH - Extract month
DAY - Extract day
HOUR - Extract hour
MINUTE - Extract minute
SECOND - Extract second
DAYNAME - Day name
MONTHNAME - Month name
DAYOFWEEK - Day of week (1-7)
DAYOFYEAR - Day of year
WEEK - Week number
DATEDIFF - Date difference
TIMEDIFF - Time difference
DATE_ADD - Add time interval
DATE_SUB - Subtract time interval
DATE_FORMAT - Format date
STR_TO_DATE - Convert string to date
UNIX_TIMESTAMP - Convert to timestamp
FROM_UNIXTIME - Convert from timestamp
Conditional Functions
IF - Simple conditional
CASE - Complex conditional
IFNULL - Handle NULL values
NULLIF - Return NULL if equal
COALESCE - Return first non-NULL value
ISNULL - Check if NULL
JSON Functions (MySQL 5.7+)
JSON_EXTRACT - Extract JSON value
JSON_UNQUOTE - Remove quotes from JSON value
JSON_OBJECT - Create JSON object
JSON_ARRAY - Create JSON array
JSON_CONTAINS - Check if JSON contains value
JSON_KEYS - Get JSON keys
JSON_LENGTH - Get JSON length
JSON_TYPE - Get JSON type
JSON_VALID - Validate JSON
JSON_INSERT - Insert JSON value
JSON_SET - Set JSON value
JSON_REPLACE - Replace JSON value
JSON_REMOVE - Remove JSON key
JSON_MERGE - Merge JSON objects
JSON_SEARCH - Search in JSON
JSON_ARRAYAGG - Aggregate to JSON array
JSON_OBJECTAGG - Aggregate to JSON object
Last updated