MySQL
Что-то мне как-то не здоровится:
(SELECT SQL_CACHE `comments`.`added` AS `ts`,
`users`.`name` AS `s_name`,
`users`.id AS `s_uid`,
`users`.`sex` AS `s_sex`,
`users`.`avatar` AS `s_icon`,
'add-article-comment' AS `action`,
`comments`.`id` AS `a_id`,
`comments`.`content` as `a_content`,
CONCAT('/articles/',`articles`.`alink`,'/#', `comments`.`id`) AS `a_link`,
'' AS `a_icon`,
`articles`.`id` AS `t_id`,
`articles`.`title` as `t_content`,
CONCAT('/articles/',`articles`.`alink`,'/') AS `t_link`,
`articles`.`thumbnail` AS `t_icon`
FROM `comments`
INNER JOIN `articles` ON (`comments`.`obj` = `articles`.`id`
AND `comments`.`module` = 3)
INNER JOIN `users` ON (`comments`.`uid` = `users`.`id`)
WHERE `comments`.`moderated` = 1
ORDER BY `comments`.`added` DESC
LIMIT 20)
UNION (
SELECT SQL_CACHE questions.`date` AS `ts`,
`users`.`name` AS `s_name`,
`users`.id AS `s_uid`,
`users`.`sex` AS `s_sex`,
`users`.`avatar` AS `s_icon`,
'add-question' AS `action`,
`questions`.`id` AS `a_id`,
`questions`.`head` as `a_content`,
CONCAT('/qa/',questions.`link`,'/') AS `a_link`,
'' AS `a_icon`,
'' AS `t_id`,
'' as `t_content`,
'' AS `t_link`,
'' AS `t_icon`
FROM `questions`
INNER JOIN `users` ON (`questions`.`uid` = users.`id`)
WHERE `questions`.`show` = 1
ORDER BY `questions`.`date` DESC
LIMIT 10
) UNION (
SELECT SQL_CACHE answers.`date` AS `ts`,
`users`.`name` AS `s_name`,
`users`.id AS `s_uid`,
`users`.`sex` AS `s_sex`,
`users`.`avatar` AS `s_icon`,
'add-answer' AS `action`,
`answers`.`id` AS `a_id`,
answers.`answer` as `a_content`,
concat('/qa/', questions.`link`, '/#', `answers`.`id`) AS `a_link`,
'' AS `a_icon`,
`questions`.`id` AS `t_id`,
`questions`.`head` as `t_content`,
CONCAT('/qa/',questions.`link`,'/') AS `t_link`,
'' AS `t_icon`
FROM answers
INNER JOIN `questions` ON (answers.`question` = questions.`id`)
INNER JOIN `users` ON (`answers`.`uid` = users.`id`)
WHERE answers.`show` = 1
ORDER BY answers.`date` DESC
LIMIT 20
)
UNION (SELECT SQL_CACHE `articles`.`pdate` AS `ts`,
`users`.`name` AS `s_name`,
`users`.id AS `s_uid`,
`users`.`sex` AS `s_sex`,
`users`.`avatar` AS `s_icon`,
'add-article' AS `action`,
`articles`.`id` AS `a_id`,
`articles`.`title` as `a_content`,
concat('/articles/', `alink`, '/') AS `a_link`,
`articles`.`thumbnail` AS `a_icon`,
'' AS `t_id`,
'' as `t_content`,
'' AS `t_link`,
'' AS `t_icon`
FROM `articles`
INNER JOIN `users` ON (`articles`.`uid` = users.`id`)
WHERE articles.`pdate` <= now() AND
articles.aactive = 1
ORDER BY articles.`pdate` DESC
LIMIT 5)
UNION
(SELECT SQL_CACHE `comments`.`added` AS `ts`,
`users`.`name` AS `s_name`,
`users`.id AS `s_uid`,
`users`.`sex` AS `s_sex`,
`users`.`avatar` AS `s_icon`,
'add-news-comment' AS `action`,
`comments`.`id` AS `a_id`,
`comments`.`content` as `a_content`,
CONCAT('/news/',`news_categories`.`link`,'/',REPLACE(`news_content`.`bdate`,'-','/'),'/#', `comments`.`id`) AS `a_link`,
'' AS `a_icon`,
`news_content`.`id` AS `t_id`,
`news_content`.`title` as `t_content`,
CONCAT('/news/',`news_categories`.`link`,'/',REPLACE(`news_content`.`bdate`,'-','/'),'/') AS `t_link`,
`news_content`.`thumbnail` AS `t_icon`
FROM `comments`
INNER JOIN `news_content` ON (`comments`.`obj` = `news_content`.`id`
AND `comments`.`module` = 2)
INNER JOIN `news_categories` ON (`news_content`.`id_cat` = `news_categories`.`id_cat`)
INNER JOIN `users` ON (`comments`.`uid` = `users`.`id`)
WHERE `comments`.`moderated` = 1
ORDER BY `comments`.`added` DESC
LIMIT 15)
ORDER BY ts DESC LIMIT 20