1
我需要组合各种MySQL表以获得共同的结果。需要的和预期的结果是网站上最后的X条评论的列表,但这些表是个人的,如:news_comments,pages_comments等。单独地,这个表具有JOINS到用户数据库。合并两个不同的MySQL表,将其排序并将其限制为合并结果
的这个意见表3的结构是:
news_comments, pages_comments, other_comments
id int ai
id_new/id_page/id_other int
id_user int
comment text
created int (timestamp)
用户表:
id int ai
login int
password varchar
...
我没有完成最后因为我们只需要ID和登录。
正常使用该查询(个人)的有:
SELECT users.id, users.login, news_comments.*, news_comments.id AS id_comment
FROM users, news_comments
WHERE users.id=news_comments.id_user AND news_comments.id_new=$id
ORDER BY created DESC
LIMIT $offset,$rows
而且工作得很好!
但在后端我想有一个网站上的所有评论列表,以温和和控制它。我需要结合所有评论表,按创建的desc进行排序,并限制结果以进行分页。
我使用MySQL和PHP,所以如果我需要使用PHP,那就没有问题了。
我该怎么做?
在此先感谢!
+1好的评论有关将限制内查询。 – davek 2010-12-21 08:03:58