I want to create a query where I can compare all columns in a table with my text and get the results. Something like this,
$query="SELECT * FROM table_name WHERE `column1` LIKE '%text%', `column2`LIKE '%text%', `column3` LIKE '%text%' ......`columnN` LIKE '%text%'
Helps are appreciated.
You can use a FULLTEXT index:
This is not only easier to code, but it can run hundreds of times faster than using wildcard patterns
LIKE '%text%'.Note you must list the same columns in your MATCH() clause as the columns you specified for the index.
Another suggestion: if the multiple columns (column1, etc.) are really multiple values for the same type of thing, you should put them in a child table.
Re your questions about getting errors:
My apologies, my example above was incomplete.
CREATE INDEXrequires that you give the index a name. For example:Also if you use back-ticks, be careful to use them properly, to delimit table names or column names. You seem to have imbalanced back-ticks.