开发者

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

开发者 https://www.devze.com 2022-12-17 02:24 出处:网络
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

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

精彩评论

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

关注公众号