
- 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
How can I use MySQL INTERVAL() function with a column of a table?
We can use INTERVAL() function with a column of a table by providing the first argument as the name of the column. In this case, al the values in that column would be compared with the values given as the other arguments of INTERVAL() function and on that basis of comparison, the result set is provided. To understand it, the data from the employee table is used which is as follows −
mysql> Select* from employee568; +----+--------+--------+ | ID | Name | Salary | +----+--------+--------+ | 1 | Gaurav | 50000 | | 2 | Rahul | 20000 | | 3 | Advik | 25000 | | 4 | Aarav | 65000 | | 5 | Ram | 20000 | | 6 | Mohan | 30000 | | 7 | Aryan | NULL | | 8 | Vinay | NULL | +----+--------+--------+ 8 rows in set (0.00 sec) mysql> Select * from employee WHERE INTERVAL(ID,4) > 0; +----+-------+--------+ | ID | Name | Salary | +----+-------+--------+ | 4 | Aarav | 65000 | | 5 | Ram | 20000 | | 6 | Mohan | 30000 | | 7 | Aryan | NULL | | 8 | Vinay | NULL | +----+-------+--------+ 5 rows in set (0.00 sec)
The above result set has 5 rows of ID = 4 to 8 as the INTERVAL function has greater than 0 values for these rows.
- Related Articles
- How can we use MySQL EXPORT_SET() function with column of a table?
- How can we add a time interval to date stored in a column of MySQL table?
- How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
- How can I create a MySQL table with a column with only 3 possible given values?
- How can I use another MySQL function/s with REPEAT() function?
- How can I use SPACE() function along with MySQL’s column data?
- How can I update MySQL table after quoting the values of a column with a single quote?
- How can I drop an existing column from a MySQL table?
- How can I remove every column in a table in MySQL?
- How can I use the arithmetic operators (+,-,*,/) with unit values of INTERVAL keyword in MySQL?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- How can I use SPACE() function with MySQL WHERE clause?
- Can we use INTERVAL keyword while inserting date records in a MySQL table?
- How can I use MySQL OCTET_LENGTH() function to count the number of characters stored in a data column?
- How can column data values of a table be compared using MySQL STRCMP() function?

Advertisements