How to search a term in more than one table field

Asked

Viewed 1,487 times

2

How do I search for a term in more than one table field in Mysql? For example, I have a website of a furniture store and the customer can search for the term "chair" and this term is in the fields description, summary and details, I would like to search in all fields. I read about select * from all_tables, but I couldn’t get what I needed.

  • you know the phpmyadmin in it has a search field and in it it is possible to perform query in more than one field, execute a query in it and see sql output rest and softness

1 answer

5


Usually just search the result of all concatenated terms:

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

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

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

  • Thank you @Bacco for the excellent tips and suggestions, I’m doing tests with all of them and the feedback has been excellent.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.