Answer the question
In order to leave comments, you need to log in
How to make a selection with multiple values in one cell?
There is a list of goods with certain IDs and there is a list of stores with their own IDs. Each store can have several products, for example, a store with ID 1 has products ID - 1,2,3,4. How can you make a selection of products if you select products that have several id values of the store to which they belong. Because to make a separate table with the content - product 1 - store 2, product 1 - store 3, product 2 - store 4 - this is a huge amount of data if there are 40 such products, and 100 stores are acceptable, and for each such product and for each store you need make your request to understand if there is a connection between them or not.
Answer the question
In order to leave comments, you need to log in
First of all, I advise you to learn Russian, since such a stream of consciousness is very difficult to read.
On business. I propose to consider for a start a simple implementation from opencrart'a.
product table:
- id
- name
- ...
store table:
- id
- name
- ...
product_to_store table:
- product_id
- store_id
Query to fetch all product data with the names of stores that have them:
SELECT
product.*,
GROUP_CONCAT(store.`name`) AS 'stores'
FROM
`product`
JOIN `product_to_store` ON product_to_store.`product_id`=product.`id`
JOIN `store` ON store.`id`=product_to_store.`store_id`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question