Skip to main content

MySQL Reference

MySQL Functions

Aggregates

See the official docs for more information. The Docs link for each function points to that function's reference in the official docs. The Tutorial link for each function, if there is one, points to that function's reference on the MySQL tutorial site.

Aggregate functionDocsTutorialDescription
AVG()DocsTutorialReturn the average value of the argument
COUNT()DocsTutorialReturn a count of the number of rows returned
GROUP_CONCAT()DocsTutorialReturn a concatenated string
MAX()DocsTutorialReturn the maximum value
MIN()DocsTutorialReturn the minimum value
STDDEV()DocsTutorialReturn the population standard deviation
SUM()DocsTutorialReturn the sum
BIT_AND()DocsReturn bitwise AND
BIT_ORDocsReturn bitwise OR
BIT_XORDocsReturn bitwise XOR
COUNT(DISTINCT)DocsReturn the count of a number of different values
JSON_ARRAYAGG()DocsReturn result set as a single JSON array
JSON_OBJECTAGG()DocsReturn result set as a single JSON object
STD()DocsReturn the population standard deviation
STDDEV_POP()DocsReturn the population standard deviation
STDDEV_SAMP()DocsReturn the sample standard deviation
VAR_POP()DocsReturn the population standard variance
VAR_SAMP()DocsReturn the sample variance
VARIANCE()DocsReturn the population standard variance

Strings

See the official docs for more information. The Docs link for each function points to that function's reference in the official docs. The Tutorial link for each function, if there is one, points to that function's reference on the MySQL tutorial site.

Aggregate functionDocsTutorialDescription
CONCAT()DocsTutorialReturn concatenated string
FIND_IN_SET()DocsTutorialIndex (position) of first argument within second argument
FORMAT()DocsTutorialReturn a number formatted to specified number of decimal places
INSTR()DocsTutorialReturn the index of the first occurrence of substring
LEFT()DocsTutorialReturn the leftmost number of characters as specified
LENGTH()DocsTutorialReturn the length of a string in bytes
LOWER()DocsTutorialReturn the argument in lowercase
LTRIM()DocsTutorialRemove leading spaces
REPLACE()DocsTutorialReplace occurrences of a specified string
RIGHT()DocsTutorialReturn the specified rightmost number of characters
RTRIM()DocsTutorialRemove trailing spaces
SUBSTRING()DocsTutorialReturn the substring as specified
SUBSTRING_INDEX()DocsTutorialReturn a substring from a string before the specified number of occurrences of the delimiter
TRIM()DocsTutorialRemove leading and trailing spaces
UPPER()DocsTutorialConvert to uppercase
ASCII()DocsReturn numeric value of left-most character
BIN()DocsReturn a string containing binary representation of a number
BIT_LENGTH()DocsReturn length of argument in bits
CHAR()DocsReturn the character for each integer passed
CHAR_LENGTH()DocsReturn number of characters in argument
CHARACTER_LENGTH()DocsSynonym for CHAR_LENGTH()
CONCAT_WS()DocsReturn concatenate with separator
ELT()DocsReturn string at index number
EXPORT_SET()DocsReturn a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string
FIELD()DocsIndex (position) of first argument in subsequent arguments
FROM_BASE64()DocsDecode base64 encoded string and return result
HEX()DocsHexadecimal representation of decimal or string value
INSERT()DocsInsert substring at specified position up to specified number of characters
LCASE()DocsSynonym for LOWER()
LIKEDocsSimple pattern matching
LOAD_FILE()DocsLoad the named file
LOCATE()DocsReturn the position of the first occurrence of substring
LPAD()DocsReturn the string argument, left-padded with the specified string
MAKE_SET()DocsReturn a set of comma-separated strings that have the corresponding bit in bits set
MATCHDocsPerform full-text search
MID()DocsReturn a substring starting from the specified position
NOT LIKEDocsNegation of simple pattern matching
NOT REGEXPDocsNegation of REGEXP
OCT()DocsReturn a string containing octal representation of a number
OCTET_LENGTH()DocsSynonym for LENGTH()
ORD()DocsReturn character code for leftmost character of the argument
POSITION()DocsSynonym for LOCATE()
QUOTE()DocsEscape the argument for use in an SQL statement
REGEXPDocsWhether string matches regular expression
REGEXP_INSTR()DocsStarting index of substring matching regular expression
REGEXP_LIKE()DocsWhether string matches regular expression
REGEXP_REPLACE()DocsReplace substrings matching regular expression
REGEXP_SUBSTR()DocsReturn substring matching regular expression
REPEAT()DocsRepeat a string the specified number of times
REVERSE()DocsReverse the characters in a string
RLIKEDocsWhether string matches regular expression
RPAD()DocsAppend string the specified number of times
SOUNDEX()DocsReturn a soundex string
SOUNDS LIKEDocsCompare sounds
SPACE()DocsReturn a string of the specified number of spaces
STRCMP()DocsCompare two strings
SUBSTR()DocsReturn the substring as specified
TO_BASE64()DocsReturn the argument converted to a base-64 string
UCASE()DocsSynonym for UPPER()
UNHEX()DocsReturn a string containing hex representation of a number
WEIGHT_STRING()DocsReturn the weight string for a string

Math

See the official docs for more information. The Docs link for each function points to that function's reference in the official docs. The Tutorial link for each function, if there is one, points to that function's reference on the MySQL tutorial site.

FunctionDocsTutorialDescription
ABS()DocsTutorialReturn the absolute value
CEIL()DocsTutorialReturn the smallest integer value not less than the argument
FLOOR()DocsTutorialReturn the largest integer value not greater than the argument
MOD()DocsTutorialReturn the remainder
ROUND()DocsTutorialRound the argument
TRUNCATE()DocsTutorialTruncate to specified number of decimal places
ACOS()DocsReturn the arc cosine
ASIN()DocsReturn the arc sine
ATAN()DocsReturn the arc tangent
ATAN2(), ATAN()DocsReturn the arc tangent of the two arguments
CEILING()DocsReturn the smallest integer value not less than the argument
CONV()DocsConvert numbers between different number bases
COS()DocsReturn the cosine
COT()DocsReturn the cotangent
CRC32()DocsCompute a cyclic redundancy check value
DEGREES()DocsConvert radians to degrees
EXP()DocsRaise to the power of
LN()DocsReturn the natural logarithm of the argument
LOG()DocsReturn the natural logarithm of the first argument
LOG10()DocsReturn the base-10 logarithm of the argument
LOG2()DocsReturn the base-2 logarithm of the argument
PI()DocsReturn the value of pi
POW()DocsReturn the argument raised to the specified power
POWER()DocsReturn the argument raised to the specified power
RADIANS()DocsReturn argument converted to radians
RAND()DocsReturn a random floating-point value
SIGN()DocsReturn the sign of the argument
SIN()DocsReturn the sine of the argument
SQRT()DocsReturn the square root of the argument
TAN()DocsReturn the tangent of the argument

Dates

See the official docs for more information. The Docs link for each function points to that function's reference in the official docs. The Tutorial link for each function, if there is one, points to that function's reference on the MySQL tutorial site. Immediately below are date formatting specifiers (which can all be seen in the MySQL docs under DATE_FORMAT).

Date format specifiers and descriptions
SpecifierDescription
%aAbbreviated weekday name (Sun..Sat)
%bAbbreviated month name (Jan..Dec)
%cMonth, numeric (0..12)
%DDay of the month with English suffix (0th, 1st, 2nd, 3rd, )
%dDay of the month, numeric (00..31)
%eDay of the month, numeric (0..31)
%fMicroseconds (000000..999999)
%HHour (00..23)
%hHour (01..12)
%IHour (01..12)
%iMinutes, numeric (00..59)
%jDay of year (001..366)
%kHour (0..23)
%lHour (1..12)
%MMonth name (January..December)
%mMonth, numeric (00..12)
%pAM or PM
%rTime, 12-hour (hh:mm:ss followed by AM or PM)
%SSeconds (00..59)
%sSeconds (00..59)
%TTime, 24-hour (hh:mm:ss)
%UWeek (00..53), where Sunday is the first day of the week; WEEK() mode 0
%uWeek (00..53), where Monday is the first day of the week; WEEK() mode 1
%VWeek (01..53), where Sunday is the first day of the week; WEEK() mode 2; used with %X
%vWeek (01..53), where Monday is the first day of the week; WEEK() mode 3; used with %x
%WWeekday name (Sunday..Saturday)
%wDay of the week (0=Sunday..6=Saturday)
%XYear for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%xYear for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%YYear, numeric, four digits
%yYear, numeric (two digits)
%%A literal % character
%xx, for any “x” not listed above
FunctionDocsTutorialDescription
CURDATE()DocsTutorialReturn the current date
DATE_ADD()DocsTutorialAdd time values (intervals) to a date value
DATE_FORMAT()DocsTutorialFormat date as specified
DATE_SUB()DocsTutorialSubtract a time value (interval) from a date
DATEDIFF()DocsTutorialSubtract two dates
DAY()DocsTutorialSynonym for DAYOFMONTH()
DAYNAME()DocsTutorialReturn the name of the weekday
DAYOFWEEK()DocsTutorialReturn the weekday index of the argument
EXTRACT()DocsTutorialExtract part of a date
LAST_DAYDocsTutorialReturn the last day of the month for the argument
MONTH()DocsTutorialReturn the month from the date passed
NOW()DocsTutorialReturn the current date and time
STR_TO_DATE()DocsTutorialConvert a string to a date
SYSDATE()DocsTutorialReturn the time at which the function executes
TIMEDIFF()DocsTutorialSubtract time
TIMESTAMPDIFF()DocsTutorialSubtract an interval from a datetime expression
WEEK()DocsTutorialReturn the week number
WEEKDAY()DocsTutorialReturn the weekday index
YEAR()DocsTutorialReturn the year
ADDDATE()DocsAdd time values (intervals) to a date value
ADDTIME()DocsAdd time
CONVERT_TZ()DocsConvert from one time zone to another
CURRENT_DATE(), CURRENT_DATEDocsSynonyms for CURDATE()
CURRENT_TIME(), CURRENT_TIMEDocsSynonyms for CURTIME()
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMPDocsSynonyms for NOW()
CURTIME()DocsReturn the current time
DATE()DocsExtract the date part of a date or datetime expression
DAYOFMONTH()DocsReturn the day of the month (0-31)
DAYOFYEAR()DocsReturn the day of the year (1-366)
FROM_DAYS()DocsConvert a day number to a date
FROM_UNIXTIME()DocsFormat Unix timestamp as a date
GET_FORMAT()DocsReturn a date format string
HOUR()DocsExtract the hour
LOCALTIME(), LOCALTIMEDocsSynonym for NOW()
LOCALTIMESTAMP, LOCALTIMESTAMP()DocsSynonym for NOW()
MAKEDATE()DocsCreate a date from the year and day of year
MAKETIME()DocsCreate time from hour, minute, second
MICROSECOND()DocsReturn the microseconds from argument
MINUTE()DocsReturn the minute from the argument
MONTHNAME()DocsReturn the name of the month
PERIOD_ADD()DocsAdd a period to a year-month
PERIOD_DIFF()DocsReturn the number of months between periods
QUARTER()DocsReturn the quarter from a date argument
SEC_TO_TIME()DocsConverts seconds to 'hh:mm:ss' format
SECOND()DocsReturn the second (0-59)
SUBDATE()DocsSynonym for DATE_SUB() when invoked with three arguments
SUBTIME()DocsSubtract times
TIME()DocsExtract the time portion of the expression passed
TIME_FORMAT()DocsFormat as time
TIME_TO_SEC()DocsReturn the argument converted to seconds
TIMESTAMP()DocsWith a single argument, this function returns the date or datetime expression; with two arguments, the sum of the arguments
TIMESTAMPADD()DocsAdd an interval to a datetime expression
TO_DAYS()DocsReturn the date argument converted to days
TO_SECONDS()DocsReturn the date or datetime argument converted to seconds since Year 0
UNIX_TIMESTAMP()DocsReturn a Unix timestamp
UTC_DATE()DocsReturn the current UTC date
UTC_TIME()DocsReturn the current UTC time
UTC_TIMESTAMP()DocsReturn the current UTC date and time
WEEKOFYEAR()DocsReturn the calendar week of the date (1-53)
YEARWEEK()DocsReturn the year and week

Comparison

See the official docs for more information. The Docs link for each function points to that function's reference in the official docs. The Tutorial link for each function, if there is one, points to that function's reference on the MySQL tutorial site.

FunctionDocsTutorialDescription
COALESCE()DocsTutorialReturn the first non-NULL argument
GREATEST()DocsTutorialReturn the largest argument
IS NULLDocsTutorialNULL value test
LEAST()DocsTutorialReturn the smallest argument
>DocsGreater than operator
>=DocsGreater than or equal operator
<DocsLess than operator
<>, !=DocsNot equal operator
<=DocsLess than or equal operator
<=>DocsNULL-safe equal to operator
=DocsEqual operator
BETWEEN ... AND ...DocsWhether a value is within a range of values
IN()DocsWhether a value is within a set of values
INTERVAL()DocsReturn the index of the argument that is less than the first argument
ISDocsTest a value against a boolean
IS NOTDocsTest a value against a boolean
IS NOT NULLDocsNOT NULL value test
ISNULL()DocsTest whether the argument is NULL
LIKEDocsSimple pattern matching
NOT BETWEEN ... AND ...DocsWhether a value is not within a range of values
NOT IN()DocsWhether a value is not within a set of values
NOT LIKEDocsNegation of simple pattern matching
STRCMP()DocsCompare two strings

Window Functions

See the official docs for more information. The Docs link for each function points to that function's reference in the official docs. The Tutorial link for each function points to that function's reference on the MySQL tutorial site.

FunctionDocsTutorialDescription
CUME_DIST()DocsTutorialCumulative distribution value
DENSE_RANK()DocsTutorialRank of current row within its partition, without gaps
FIRST_VALUE()DocsTutorialValue of argument from first row of window frame
LAG()DocsTutorialValue of argument from row lagging current row within partition
LAST_VALUE()DocsTutorialValue of argument from last row of window frame
LEAD()DocsTutorialValue of argument from row leading current row within partition
NTH_VALUE()DocsTutorialValue of argument from N-th row of window frame
NTILE()DocsTutorialBucket number of current row within its partition.
PERCENT_RANK()DocsTutorialPercentage rank value
RANK()DocsTutorialRank of current row within its partition, with gaps
ROW_NUMBER()DocsTutorialNumber of current row within its partition

Control Flow Functions and Expressions

See the official docs for more information. The Docs link for each function points to that function's reference in the official docs. The Tutorial link for each function, if there is one, points to that function's reference on the MySQL tutorial site.

FunctionDocsTutorialDescription
CASEDocsTutorialCase operator
IF()DocsTutorialIf/else construct
IFNULL()DocsTutorialNull if/else construct
NULLIFDocsTutorialReturn NULL if expr1 = expr2