MySQL Subquery LIMIT

折月煮酒 提交于 2020-01-09 03:33:04

问题


As the title says, I wanted a workaround for this...

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))

Cheers


回答1:


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

You probably will want to add an ORDER BY into the nested query.



来源:https://stackoverflow.com/questions/2856397/mysql-subquery-limit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!