开发者

Selecting the items associated with a tag along with the tags associated with these items

2 table开发者_如何学编程s:

items(item_id, ...)

tags(tag_id, item_id)

How do I select the items (from the "items" table) that have a particular tag associated with them (in the "tags" table) along with all the tags associated with these items?


Use:

SELECT i.*, 
       t.tag_id
  FROM ITEMS i
  JOIN TAGS t ON t.item_id = i.item_id
 WHERE i.item_id IN (SELECT x.item_id
                       FROM TAGS x 
                      WHERE x.tag_id = ?)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜