代码之家  ›  专栏  ›  技术社区  ›  Atif

MySQL子查询限制

  •  16
  • Atif  · 技术社区  · 15 年前

    SELECT 
      comments.comment_id,
      comments.content_id,
      comments.user_id,
      comments.`comment`,
      comments.comment_time,
      NULL
    FROM
      comments
    WHERE
      (comments.content_id IN (SELECT content.content_id FROM content WHERE content.user_id = 1 LIMIT 0, 10))
    

    1 回复  |  直到 15 年前
        1
  •  18
  •   Quassnoi    15 年前
    SELECT  comments.comment_id,
            comments.content_id,
            comments.user_id,
            comments.`comment`,
            comments.comment_time,
            NULL
    FROM    (
            SELECT  content.content_id
            FROM    content
            WHERE   content.user_id = 1
            LIMIT 10
            ) q
    JOIN    comments
    ON      comments.content_id = q.content_id
    

    您可能需要添加 ORDER BY