- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 −
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.
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.
Kickstart Your Career
Get certified by completing the courseGet Started