php - How do I combine select statements for all values in a many-to-many table -
I am working on the existing product database trying to clean things. I have the following tablets:
Tables
& lt; Products & gt; ID, title & lt; Keyword & gt; ID, title & lt; Product_has_keyword & gt; Product_id, keyword_id
When I want to prepare a list of products, I use the code:
from SELECT * products;
And then for each product:
Search by keywords k.title k, product_has_keyword phk WHERE k.id = phk.keyword_id and phk.id =?
How can I change this code in a single SELECT which also returns products like "ID, title, keyword" to keywords (apart from spaces)?
Such as (1, "Hummer", "Equipment house hand"), (2, "blender", "kitchen house"), etc ...
You can use it but it may be aware that its group has a character limit
SELECT p.id, p.title, GROUP_CONCAT (K.title SEPARATOR '') Products from 'keyword' P LEFT JOIN product_has_keyword phk ON (P.ID = phk.product_id) On lower zone keywords (k.id = phk. Keyword_id) WHERE phk.id =? P.id
Comments
Post a Comment