Possible Duplicates:
MYSQL query for searching through ALL the fields? MySQL - Search in all fields from every table from a database
I have 28 fields in a table and one option I would like to give a user is to search every entry across all its fields. So Instead of writing something like this:
SELECT * FROM table WHERE field1 LIKE testfield OR field2 LIKE testfield OR field3 LIK开发者_如何学GoE testfield
OR field4 LIKE testfield OR ... etc
I would like to write something like this:
SELECT * FROM table WHERE * LIKE testfield;
This doesnt work so I wondering if there is another syntax or the feature doesnt exist?
There's no portable support for this type of query in SQL. Your best bet is to create another string/varchar column and concat the other columns into a string and then search on that.
SQL Server does support a contains keyword:
SELECT Name, Color FROM Production.Product
WHERE CONTAINS((Name, Color), 'Red');
But, if you want to be portable, you're better off with the extra column.
精彩评论