MySQL Limit with Many to Many Relationship

后端 未结 4 663
傲寒
傲寒 2021-02-06 18:43

Given a SCHEMA for implementing tags

ITEM ItemId, ItemContent

TAG TagId, TagName

ITEM_TAG ItemId, TagId

What is the best way to limit the number

4条回答
  •  孤城傲影
    2021-02-06 19:06

    Maybe something like

    select i.ItemContent, t.TagName from (SELECT ItemId, ItemContent FROM item limit 10) i
    INNER JOIN ItemTag it ON i.ItemId = it.ItemId --You will miss tagless items here!
    INNER JOIN tag t ON t.id = it.TagId
    

提交回复
热议问题