Learn MySQL

MySQL Function

List Of important MySQL function are given below.

  • MySQL aggregate functions
  • MySQL string functions
  • MySQL control flow functions
  • MySQL date and time functions

MySQL aggregate functions

Function Name Description
AVG() MySQL AVG function is used to calculate the average of a field in various records.
COUNT() MySQL AVG function is used count the number rows in a table.
COUNT() MySQL COUNT function is used count the number rows in a table.
SUM() MySQL SUM function return the sum of certain column .
MIN() MySQL MIN function return the minimum value of certain column .
MAX() MySQL MAX function return the maximum value of certain column .
GROUP_CONCAT() MySQL GROUP_CONCAT function is used to concatenate column values into a single string .

MySQL string functions

Function Name Description
CONCAT() MySQL CONCAT function is used to combines two or more strings into one string.
LENGTH() MySQL LENGTH function return the length of a string in bytes.
CHAR_LENGTH() MySQL CHAR_LENGTH function return number of characters in string .
REPLACE() MySQL REPLACE function replace occurrences of a specified string.
SUBSTRING() MySQL SUBSTRING function extracts number of characters from a particular position of a specified string.
FIND_IN_SET() MySQL FIND_IN_SET function returns the first position of a string if it is present within a list of strings.FIND_IN_SET function returns 0 when search string does not exist in the string list.
TRIM() MySQL TRIM function returns a string after removing all specified characters either from the beginning or the ending of a string.
INSERT() MySQL INSERT function Insert a substring in to a string at the specified position up to the specified number of characters.
LOWER() MySQL LOWER function converts all characters in the specified string to lowercase.
UPPER() MySQL UPPER function converts all characters in the specified string to uppercase.
LOAD_FILE() MySQL LOAD_FILE function reads the file and returns the file contents as a string.
LOCATE() MySQL LOCATE function return the position of the first occurrence of substring.

MySQL control flow functions

Function Name Description
IF() MySQL IF function returns a value based on a given condition.
IFNULL () MySQL IFNULL function takes two argument and if the first argument is not NULL, it returns the first argument. Otherwise it returns the second argument. .
NULLIF() MySQL NULLIF function returns NULL when the first is equal to the second argument, other wise it returns the first argument.

MySQLdate and time functions

Function Name Description
DATEDIFF() MySQL DATEDIFF function returns the number of days between two dates or datetimes.
DATE_FORMAT() MySQL DATE_FORMAT function formats a date value based on a specified date format.
STR_TO_DATE() MySQL DATE_FORMAT function takes a string and returns a date.
NOW() MySQL DATE_FORMAT function returns the value of current date and time .
CURTIME() MySQL CURTIME function returns the value of current time in HH:MM:SS format or HHMMSS.uuuuuu .
DAY() MySQL DAY function returns the day (1 to 31) of the month for a specified date.
MONTH() MySQL MONTH function returns the month (1 to 12) for a specified date.
WEEK() MySQL WEEK function returns the week number for a given date.
YEAR() MySQL YEAR function returns the year for a given date.