In MySQL Advanced Function Part-5 we will discuss about the LAST_INSERT_ID, LEAST, LOAD_FILE, MASTER_POS_WAIT, NULLIF, SESSION_USER, SYSTEM_USER, USER, VERSION
LEAST Function:- The LEAST Function is used for returning the least value of the given list of arguments.
Syntax:- LEAST(arg1, arg2,arg3,….)
Example:-
SELECT LEAST(13, 15, 3, 9, 2);
Output:- 2
SELECT LEAST(“kshtutor.com”, “srkpgroup.com”, “facebook.com”);
output:- facebook.com
LOAD_FILE Function:- LOAD_FILE Function is used for reading files and returning the file content as a string.
Syntax:- LOAD_FILE(File path/file name)
Example:- SELECT * LOAD_FILE(“c:/filefolder/filename.txt”);
MASTER_POS_WAIT Function:- MASTER_POS_WAIT Function is also called MASTER_POS_WAIT() statement, But it is actually a function. It is used to ensure that the replica has read and executed events up to a given position in the source’s binary log.
From MySQL version 8.0.26 this function is deprecated and instead of this, we can use SOURCE_POS_WAIT() function.
LAST_INSERT_ID Function:- LAST_INSERT_ID Function is used to return the last AUTO_INCREMENT id. It is used after INSERT or UPDATE statement.
Syntax:- LAST_INSERT_ID(expression)
NULLIF Function:- NULLIF Function is used to compare two expressions. If both expressions are equal then it will return NULL otherwise It will return the first expression.
Syntax:- NULLIF(expr1, expr2)
Example:-
SELECT NULLIF(12,12);
Output:- NULL
SELECT NULLIF(“Red”, 13);
Output:- Red
SESSION_USER Function, SYSTEM_USER Function, and USER Function:- SESSION_USER Function, SYSTEM_USER Function, and USER Function are used for returning the USERNAME and HOST name of the current MySQL connection.
Syntax:-
SESSION_USER();
SYSTEM_USER();
USER();
VERSION Function:- The VERSION Function is used for returning the current version of MySQL.
Syntax:- VERSION();
Read Also:-
MySQL Advanced Function Part-1
MySQL Advanced Function Part-2
MySQL Advanced Function Part-3
MySQL Advanced Function Part-4
Read more detail about functions in the MySQL manual.