Y
Y
yurygolikov2017-04-19 22:29:21
MySQL
yurygolikov, 2017-04-19 22:29:21

Is it possible to create a composite index on fields from different tables in MySql 5.7, if not, what is the best way to organize this?

I will describe an elementary example:
1. There is a table - product (id, id_brand_product, description_product)
2. There is a table - brand_product (id, brand_name)
The 2nd table is a reference for the first one, one-to-many relationship.
How can I do a full text search in this case? As I understand it, it is impossible to hang FULLTEXT INDEX on fields from different tables (product.product_description and product_brand.brand_name). How then to proceed, still store the values ​​of the 2nd table in the first one, make separate indexes, or is there some other way?
I'm probably missing something or don't understand. I ask not to kick in designing DB - the beginner.
Thanks for answers!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-04-20
@yurygolikov

It's strange how your base is organized. Why does a brand refer to a product? And what does it look like when there are several products under one brand? According to my mind, this product should have a brand_id field.
And your problem is solved, for example, like this:

SELECT *
  FROM `items` 
  WHERE MATCH (`name`) AGAINST :searchString
    OR `brand_id` IN (SELECT `id` FROM `brands` WHERE MATCH (`name`) AGAINST :searchString)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question