Home Education What are the Functions in MySQL? Some Built-in Functions

What are the Functions in MySQL? Some Built-in Functions

Before going to Learn the MySQL Built-in Functions, let us have a classification :

MySQL Function

Direct Switch to Contents

  1. Built-in functions
  2. Aggregate Functions
  3. Math Functions
  4. String Function
  5. Date time functions
  6. Some Examples
  7. Conclusion
  8. FAQs

Let’s have a brief categorizationvia Snap:

MySQL Functions

Built-in functions

MySQL has many built-in functions.
This blog gives you the most commonly used MySQL functions including basic SQL Functions, aggregate functions, string functions, date-time functions, control flow functions, etc.

MySQL-Function

One of the basic function is SELECT DATABASE();
This function shows the current database name that is in use.
Some of the aggregate functions are SUM, AVG, MAX, MIN, and COUNT functions.
Some of the String Function is CONCAT, LENGTH, LEFT, LOWER, REPLACE, RIGHT, SUBSTRING, UPPER, TRIM Functions.

Let us take one by one by catteries.

Aggregate Functions:

Aggregate Function

AVG() :Return the average of non-NULL values.
COUNT(): Return the number of rows in a group, including rows with NULL values.
MAX() :Return the highest value (maximum) in a set of non-NULL values.
MIN() :Return the lowest value (minimum) in a set of non-NULL values.
SUM(): Return the summation of all non-NULL values a set.

Math Functions:

ABS() :Returns the absolute value of a number
CEIL(): Returns the smallest integer value greater than or equal to the input number (n).
FLOOR(): Returns the largest integer value not greater than the argument
MOD():
Returns the remainder of a number divided by another
ROUND():
Rounds a number to a specified number of decimal places.
TRUNCATE(): Truncates a number to a specified number of decimal places.

String Function

String Funtion

CONCAT : Concatenate two or more strings into a single string
INSTR : Return the position of the first occurrence of a substring in a string
LENGTH : Get the length of a string in bytes and in characters
LEFT : Get a specified number of leftmost characters from a string
LOWER : Convert a string to lowercase
LTRIM : Remove all leading spaces from a string
REPLACE : Search and replace a substring in a string
RIGHT : Get a specified number of rightmost characters from a string.
TRIM : Remove unwanted characters from a string.
FORMAT : Format a number with a specific locale, rounded to the number of decimals
UPPER : Convert a string to uppercase

Date time functions

Date & Time Function

CURDATE : Returns the current date.
DATEDIFF : Calculates the number of days between two DATE values.
DAY : Gets the day of the month of a specified date.
DATE_ADD : Adds a time value to date value.
DATE_SUB : Subtracts a time value from a date value.
DATE_FORMAT : Formats a date value based on a specified date format.
DAYNAME : Gets the name of a weekday for a specified date.
DAYOFWEEK : Returns the weekday index for a date.
EXTRACT : Extracts a part of a date.
LAST_DAY : Returns the last day of the month of a specified date
NOW : Returns the current date and time at which the statement executed.
MONTH : Returns an integer that represents a month of a specified date.
WEEK : Returns a week number of a date.
WEEKDAY : Returns a weekday index for a date.
YEAR : Return the year for a specified date.

Let us take some of the examples one by one.

INSERT FUNCTION:

The INSERT() function inserts a string within a string at the specified position and for a certain number of characters.
Syntax: INSERT(string, position, number, string2);

Parameter Description

string : Required. The string that will be modified
position : Required. The position where to insert string2
number : Required. The number of characters to replace
string2 : Required. The string to insert into the string

CONCAT()

This function is used to add two or more strings.
There may be one or more arguments.
Returns the string that results from concatenating the arguments. It also returns a nonbinary string, if all arguments are nonbinary strings.
Returns a binary string, if the arguments include any binary strings. If the argument is numeric, it is converted to its equivalent nonbinary string form. Returns NULL if any argument is NULL.

AVG()

This function retrieves the average value of a given expression. If the function does not find a matching row, it returns NULL. Where expr is given expression.

SQRT

The SQRT function returns the square root of a number.
The syntax for the SQRT function in MySQL is:
SQRT( number )

A positive number used to calculate the square root.

Note: The SQRT function will return NULL, if the number is a negative value.

SQL COUNT()

The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values. COUNT() returns 0 if there were no matching rows. The above syntax is the general SQL 2003 ANSI standard syntax

SQL UPPER function

The SQL UPPER function converts all the letters in a string into uppercase. If you want to convert a string to lowercase, you use the LOWER function instead.
The syntax of the UPPER function is as simple as below.
UPPER(string);
If the input string is NULL, the UPPER function returns NULL, otherwise, it returns a new string with all letters converted to uppercase.
Besides the UPPER function, some database systems provide you with an additional function named UCASE which is the same as the UPPER function. It is “there is more than one way to do it”.
UCASE(string);

Want To Learn More MySQL Functions Click Here.

MySQL Function

Conclusion

Here we discussed the basic knowledge functions in my SQL. There is some built-in function and I have explained a systematic way of them with examples.

FAQs

1. How to use count function in mysql?

COUNT() function is an Aggregate Function that returns the number of rows in a result set returned by a SELECT statement. The general syntax is as follow:
COUNT(expression)
The COUNT(expression) returns the number of rows that do not contain NULL values as the result of the expression.

2. What is an Aggregate Function?

An Aggregate Function summarizes the results of an expresion over a number of rows, returning a single value. The general syntax for the most Aggregate Function is as follow:
aggregate_function([Distinct|All]expresion)

3. What is the difference between Min & Max Functions?

Min returns the smallest value of a column and Max return the largest value of a column.

Next Blog | What is JOIN and Different types of JOIN Operations in MySQL?

Previous Blog | What are Keys in MySQL? Overview And Understanding

RELATED ARTICLES

5 Best Laptops Under 60000 Suitable To Your Profession

Today we live in the era of the internet in which laptops and mobile phones play an important role. So if you...

5 Best Inverters to Buy This Year | How to Choose the Right Inverter

We all know inverters are useful for getting backup of electricity, but fewer people know about all features and types. If you...

Top Selling Best Budget Smartphones That You Can Buy This Year

Are you planning to buy a smartphone? Or Looking for a budget smartphones with the best features?  Almost everyone is stuck with...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

5 Best Laptops Under 60000 Suitable To Your Profession

Today we live in the era of the internet in which laptops and mobile phones play an important role. So if you...

5 Best Inverters to Buy This Year | How to Choose the Right Inverter

We all know inverters are useful for getting backup of electricity, but fewer people know about all features and types. If you...

Top Selling Best Budget Smartphones That You Can Buy This Year

Are you planning to buy a smartphone? Or Looking for a budget smartphones with the best features?  Almost everyone is stuck with...

Top 10 Network Marketing Companies in India | Future of MLM Business

Everybody knows about marketing that it is an essential part of a business. It is essential to promote our product to others...

Recent Comments