tags:

views:

137

answers:

1

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  A: 
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.

Quassnoi
great thanks for this one.. Well another thing.. Is there a way to LIMIT comments to 2 per content_id ?
atif089
@atif089: yes, see this article: http://explainextended.com/2009/03/06/advanced-row-sampling/
Quassnoi
thanks for the link.. wouldn't this be too heavy ? As im using this for a custom made social networking website
atif089
@atif: too heavy for what?
Quassnoi
I mean its for a social networking website, and Im on a shared server. So would it be using much CPU ?
atif089
@atif: with a proper indexing, this would be very efficient.
Quassnoi
great! Thanks :)
atif089