 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
 