Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Subquery LIMIT

Tags:

mysql

subquery

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

like image 655
Atif Avatar asked May 18 '10 10:05

Atif


1 Answers

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.

like image 82
Quassnoi Avatar answered Nov 07 '22 17:11

Quassnoi