- Trending Categories
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 to search multiple columns in MySQL?
Let us understand how to search multiple columns in MySQL −
Note: We assume we have created a database named ‘DBNAME’ and a table named ‘tableName’.
The ‘AND’ and ‘OR’ operators can be used, depending on what the user wants the search to return.
Let us see that with the help of an example −
Example
SELECT colName FROM tableName WHERE my_col LIKE %$param1% AND another_col LIKE %$param2%;
In the above example, the ‘AND’ operator is used.
This means that both the clause has to match a record for the result to be returned.
Query
SELECT colName FROM tableName WHERE my_col LIKE %$param1% OR another_col LIKE %$param2%;
In the above example, the ‘OR’ operator is used. This means that either of the clause have to match a record for the result to be returned.
Advertisements