![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements