MySQL Functions

This section gives you the most commonly used MySQL functions including aggregate functions, string functions, datetime function, control flow function, etc.

MySQL aggregate functions

  • MySQL aggregate function - provides a brief overview of the most commonly used MySQL aggregate functions
  • AVG - calculates the average value of a set of values or an expression.
  • COUNT - count the number rows in a table.
  • SUM - calculates the sum of a set of values or an expression.
  • MIN - finds the minimum value in a set of values
  • MAX - finds the maximum value in a set of values

MySQL string functions

  • CONCAT - combines two or more strings into one string.
  • LENGTH and CHAR_LENGTH - get the length of strings in bytes and in characters.
  • REPLACE - searches and replaces a substring in a string.
  • SUBSTRING -  extracts a substring starting from a position with a specific length.

MySQL control flow functions

  • IF - returns a value based on a given condition
  • IFNULL - returns the first argument if it is not NULL, otherwise returns the second argument.
  • NULLIF - returns NULL if the first argument is equal to the second argument, otherwise returns the first argument.

Other MySQL Functions

  • LAST_INSERT_ID - obtains the last generated sequence number of the last inserted record.
  • DATEDIFF - calculates the number of days between two DATEs or two DATETIMEs.