1.

INBUILT FUNCTIONS IN MySQL

Answer»
  • STRING FUNCTIONS
FunctionDescription
ASCIIReturns the ASCII value of a character
CHAR_LENGTHReturns the length of a string.
CHARACTER_LENGTHReturns the length of a string
CONCATConcatenates two or more expressions.
CONCAT_WSConcatenates with a separator. 
FIELDReturns the index of value in a list.
FIND_IN_SETReturns the index of a string within a list.
FORMATChanges the format/representation.
INSERTInserts a string within a string at a given index.
INSTRReturns the index of the first occurrence of a string in another one.
LCASEConverts an entire string to lowercase.
LEFTExtracts a length of characters from the left of a string.
LENGTHReturns the string length in bytes.
LOCATEReturns the location of the first occurrence of a substring in a given  string
LOWERConverts an entire string to lowercase.
LPADLeft-pads a string with a given string.
LTRIMRemoves spaces from the left of a string.
MIDExtracts a substring from a string at a given position.
POSITIONReturns the location of the first occurrence of a substring in a given  string
REPEATRepeats the string the number of times the user specifies.    
REPLACEReplaces occurrences of a substring in a string with another substring.
REVERSEReverses the string.
RIGHTExtracts a length of characters from the right of a string.
RPADRight-pads a string with a given string.
RTRIMRemoves spaces from the right of a string.
STRCMPChecks whether two strings are equal.
SUBSTRExtracts a substring from a string at a position mentioned by the user.
SUBSTRINGSame as substr.
TRIMTrims leading and trailing spaces from a string as specified by the user.
UCASEConverts an entire string to uppercase.
UPPERConverts an entire string to uppercase.
  • NUMERIC FUNCTIONS
FunctionDescription
ABSReturns the absolute value.
ACOSReturns the cosine inverse.
ASINReturns the sine inverse.
ATANReturns the tan inverse of one or two numbers.
ATAN2Returns the tan inverse of  two numbers.
AVGReturns the mean value.
CEILReturns the smallest integer that is greater than or equal to the number
CEILINGReturns the smallest integer that is greater than or equal to the number
COSReturns the cosine.
COTReturns the cotangent.
COUNTReturns the number of records returned by a query.
DEGREESConverts angle in Radians to Degrees. 
DIVInteger division
EXPReturns e raised to the power of value mentioned.
FLOORReturns the largest integer that is less than or equal to a number
GREATESTReturns the largest value in the list.
LEASTReturns the smallest value in the list.

LN
Calculates logarithm to the base e.
LOGCalculates logarithm to the base e.
LOG10Calculates logarithm to the base 10.
LOG2Calculates logarithm to the base 2.
MAXReturns the largest value in a set.
MINReturns the least value in a set.
MODReturns the remainder after division of two numbers.
PIReturns value of π
POWUsed for exponents.
POWERUsed for exponents.
RADIANSConverts angle in Degree to Radians.
RANDGenerates a random number.
ROUNDRounds the number to the nearst decimal place.
SIGNReturns the sign of a number
SINReturns the sine.
SQRTReturns the root of a number.
SUMCalculates the sum of a set.
TANReturns the tangent.
  • MYSQL DATE FUNCTION
FunctionDescription
ADDDATEAdds a date interval and return the value.
ADDTIMEAdds a time interval and then returns the value.
CURDATEReturns today’s date
CURRENT_DATESame as CURDATE
CURRENT_TIMEReturns the time at the moment
CURRENT_TIMESTAMPReturns date and time at the moment.
CURTIMEReturns time at the moment.
DATEPicks up the date from an expression of Date/Time.
DATEDIFFReturns number of days between two given dates.
DATE_ADDSimilar to ADDDATE
DATE_FORMATChanges the format in which Date is displayed.
DATE_SUBSubtracts a time interval and returns the value.
DAYReturns the weekday for today.
DAYNAMEReturns the weekday name for any date.
DAYOFMONTHUsed to retrieve the index of the day of the month of any date.
DAYOFWEEKUsed to retrieve the index of the weekday of any date.
DAYOFYEARUsed to retrieve the index of the day of a year of any date.
EXTRACTExtracts a part of any date.
HOURReturns the “hours” in a given time.
LAST_DAYReturn the last day of the given month.
LOCALTIMEReturns the date and time at the moment.
LOCALTIMESTAMPSimilar to LOCALTIME.
MAKEDATEReturns a date based on the year and the no. of days you specify.
MAKETIMEReturns a time based on the hours , minutes and seconds you specify.
MICROSECONDReturns the microseconds in a given time.
MINUTEReturns the minutes in a given time.
MONTHReturns the month on a given date.
MONTHNAMESame as MONTH but returns the name of the month.
NOWReturns date and time at the moment.
PERIOD_ADDAdds a specific number of months.
PERIOD_DIFFReturn the difference between two time periods.
SECONDReturn the seconds in a given time.
SEC_TO_TIMEReturns time in seconds.
STR_TO_DATEFormats the date based on a particular string.
SUBDATESame as DATE_SUB.
SUBTIMESubtracts a time interval.
SYSDATEReturns the date/time reflected by the system.
TIMEReturns the time from a date/time value.
TIME_FORMATTime is displayed based on a certain format.
TIME_TO_SECReturns time in seconds.
TIMEDIFFReturns the difference between two date-time values.
TO_DAYSReturns the number of days between amy date and "0000-00-00"
  • ADVANCED MYSQL FUNCTION
FunctionDescription
BINReturns binary value of a given number.
BINARYConverts a given string to a binary string.
CASTConverts data from one data type to another.
COALESCEReturns the first non-null value in a set or list.
CONVConverts a number from one number-base system to another
CONVERTSimilar to CAST in working
CURRENT_USERReturns the user name and host name for the MySQL account that is currently used.
DATABASEReturns the name of the database currently in use.
IFIF condition statement.
SESSION_USERReturns the current MySQL user name and host name.
SYSTEM_USERSimilar to SESSION_USER.
USERSimilar to SESSION_USER.
VERSIONReturns the current version of the MySQL server installed.
CONCLUSION

By going through this cheat sheet, you would have got a decent understanding/revision of MySQL. More than memorizing syntax, do pay attention to practising them and solving problems.

Additional Resources

  • MySQL Interview Questions

  • MySQL Commands: Full List With Examples

  • Top MySQL Features

  • MySQL Vs MongoDB

  • MySQL Vs PostgreSQL

  • MySQL vs SQL




Discussion

No Comment Found