Alex Rivera | Logout

Search all columns of a table using a single where condition with single keyword in mysql

Asked 2012-09-23T06:57:41.320
23

I have a table which consists of 64 different fields. i am going to search with a single keyword in it, Results should match the keyword from any field. Give some suggestions.

Edit
Report

1 Answer

2

I can't see a way around your query being simple but long:

SET @term = "Somesearch";
SELECT id, title FROM sometable WHERE
    col1 LIKE '%@term%' OR
    col2 LIKE '%@term%' OR
    col3 LIKE '%@term%' ...;

Instead of using a MySQL variable, you can just use a language-specific variable but for the sake of examples, I thought I'd stick with MySQL itself.

The "..." is where you'd place the other 61 columns/fields.

answered 2012-09-23T07:08:11.573

Your Answer