Hello,
I have the following tables:
- Products
- Categories
- Subcategories
- Brands
with the following fields:
Products:
- id
- name
- description1
- description2
- description3
- id_category
- id_subcategory
- id_brand
Categories:
- id
- name
Subcategories
- id
- name
Brands
- id
- name
What I want is to make a query, where the user inputs 1 or more words and then search all the fields I have above.
This is my query now:
SELECT DISTINCT p. *
FROM products p, categories c, subcategories s, brands m
WHERE p.name LIKE 'word%'
OR p.description1 LIKE 'word%'
OR p.description2 LIKE 'word%'
OR p.description3 LIKE 'word%'
OR (
c.name LIKE 'word%'
AND c.id = p.id_category
)
OR (
s.name LIKE 'word%'
AND s.id = p.id_subcategory
)
OR (
m.name LIKE 'word%'
AND m.id = p.id_brand
)
LIMIT 10 ;
Is there any way to tweak this query to make it faster? The Database has quite a few products already, so I suspect the time it is taking for this query to show might be because of that..
Any sugestions?
Thank you!