如何在多对多表中为所有值组合select语句

I'm working on an existing product database trying to clean things up. I have the following tables:

Tables

<products> id, title
<keywords> id, title
<product_has_keyword> product_id, keyword_id

When I want to generate a list of products I use the code:

SELECT * FROM products;

And then for each product:

SELECT k.title FROM keywords k, product_has_keyword phk WHERE k.id = phk.keyword_id AND phk.id = ?

How would I change this code into a single SELECT that perhaps returns products in addition to the keywords (separated by spaces) like "id, title, keywords"?

Such as (1, "hammer", "tool home hand"), (2, "blender", "kitchen home"), etc...

查看全部
dongziduo9762
dongziduo9762
2014/02/17 20:26
  • select
  • php
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复