learning joins is the best way to solve such a problem
Explanation
what we are trying here to do is create a virtual table which fetches records based on some relations.
I have created three tables here
and there is a relation set between the
- product and the comments table - using product.id and comments.prod_id
- user and the comments table - using user.id and comments.user_id
Now you can use join to filter the results
SELECT product.id,user.name,comments.DATA
FROM comments
LEFT JOIN product ON comments.prod_id = product.id
INNER JOIN USER ON comments.user_id = USER.id;
or if you don't want to use join you can simply create a relation
but please do note that using joins is the best possible way to do it
SELECT product.id,USER.name,comments.DATA
FROM product,USER,comments
WHERE product.id = comments.prod_id AND USER.id = comments.user_id;
you can check the results here
SqlFiddle