Searching a term in more than one table field

2

How can I search a term in more than one field of a table in MySQL? For example, I have a website from a furniture store and the customer can search for the term "chair" and that term is in the description, summary, and detail fields, I would like to search across all fields. I read something about select * from all_tables, but I could not get what I need.

    
asked by anonymous 27.10.2014 / 20:53

1 answer

5

Normally just search the result of all the concatenated terms:

SELECT
   *
FROM
   tabela
WHERE
   CONCAT_WS( ' ', campo1,  campo2,  campo3,  campo4 ) LIKE '%termo%'

If you are looking for a way to search for multiple terms, we have some semi-duplicates on the site with a ready solution:

PS: Even if the data is in different tables, CONCAT works, as long as the JOIN is made.

    
27.10.2014 / 21:22