
- 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 get the output based on comparison done with column’s name using MySQL IN() function?
In this scenario, we need to use the name of the column as ‘Expression’ which will then be compared with the values in the list. If a column has value/s matched within the list, the output would be produced. For understanding it, consider the example from employee table having the following data −
mysql> Select * from Employee; +----+--------+--------+ | ID | Name | Salary | +----+--------+--------+ | 1 | Gaurav | 50000 | | 2 | Rahul | 20000 | | 3 | Advik | 25000 | | 4 | Aarav | 65000 | | 5 | Ram | 20000 | | 6 | Mohan | 30000 | +----+--------+--------+ 6 rows in set (0.00 sec)
Now, we can use column ‘ID’ with IN() function as follows −
mysql> Select * from Employee WHERE ID IN(6,2,3,20,10,9); +----+-------+--------+ | ID | Name | Salary | +----+-------+--------+ | 2 | Rahul | 20000 | | 3 | Advik | 25000 | | 6 | Mohan | 30000 | +----+-------+--------+ 3 rows in set (0.00 sec)
From the above result set, it is clear that IN() function matches the value of column ‘ID’ with the values in the list and gives the rows as output for which it matched.
- Related Articles
- How can we use MySQL REVERSE() function on column’s data along with WHERE clause?
- How can we use MySQL POWER() function with the column’s data values?
- How can we get sorted output based on multiple columns?
- How can I modify an existing MySQL column’s data type?
- How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- How can we get the sorted MySQL output?
- How to use REPLACE() function with column’s data of MySQL table?
- How can I get the output of multiple MySQL tables from a single query?
- Display records from two columns based on comparison in MySQL?
- How does MySQL QUOTE() function work with comparison values?
- In MySQL, how IN() comparison function works?
- How can I use another MySQL function/s with REPEAT() function?
- How to get Column name on ResultSet in Java with MySQL?
- How can I search data from MySQL table based on similar sound values?
- How can I use SPACE() function with MySQL WHERE clause?

Advertisements