
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What is MySQL INTERVAL() function?
MySQL INTERVAL() function returns the index value of the argument which is greater than the first argument.
Syntax
INTERVAL(N,N1,N2,N3,…)
Here, this function will compare 1st argument i.e. N with the other arguments i.e. N1, N2, N3 and so on. All the arguments are treated as integers. It returns the output as follows −
- If N<N1 then it returns 0
- If N<N2 then it returns 1
- If N<N3 then it returns 2 and so on…
The indexing is started with 2nd number i.e. from N1 and the first position is 0.
Example
mysql> Select INTERVAL(50,20,32,38,40,50,55); +--------------------------------+ | INTERVAL(50,20,32,38,40,50,55) | +--------------------------------+ | 5 | +--------------------------------+ 1 row in set (0.00 sec)
The above result set has 5 as its output because the index value of 55, which is the only greater number than 50, is 5.
- Related Articles
- What MySQL returns if the first argument of INTERVAL() function is NULL?
- What is MySQL ELT() function?
- What is MySQL MAKE_SET() function?
- What is MySQL OCTET_LENGTH() function?
- Why is it good to write the numbers in MySQL INTERVAL() function in ascending order?
- How MySQL behaves when we use INTERVAL of time unit with CURDATE() function?
- How can I use MySQL INTERVAL() function with a column of a table?
- What MYSQL INTERVAL() function returns if there is no bigger number in the list of arguments than the number at first argument?
- What is the use of MySQL FROM_UNIXTIME() function?
- What is the use of MySQL GET_FORMAT() function?
- What is the use of MySQL LAST_INSERT_ID() function?
- What is the use of MySQL CONCAT_WS() function?
- What is the use of MySQL TRUNCATE() function?
- What is the use of MySQL SUBSTRING_INDEX() function?
- What is the use of MySQL UNHEX() function?

Advertisements