请我有这个查询,如果组合(联合所有)使用文件排序,但如果单独执行没有文件排序可以正常工作。在这里,我不想单独执行它,但想实现 union all 选项。请有人帮忙。
(SELECT STRAIGHT_JOIN *,
topic_post_time,
topic_title,
topic_id AS tid,
p.userid AS profile_id,
Concat(first_name, ' ', last_name) AS poster_name,
Concat(first_name, '.', last_name) AS profile_name,
forum_id,
topic_last_post_time,
sch_name_abbrev,
picture_small_url,
profile_pix_upload_path,
profile_pix_upload_path,
LEFT(post_text, 100) AS post_text
FROM _forum_topics FORCE INDEX(topic_poster)
INNER JOIN _profile p
ON ( p.userid = _forum_topics.topic_poster )
INNER JOIN _users
ON p.userid = _users.userid
INNER JOIN _class
ON _users.classid = _class.classid
INNER JOIN _unit
ON _class.unitid = _unit.unitid
INNER JOIN _department
ON _unit.deptid = _department.deptid
INNER JOIN _faculty
ON _department.facid = _faculty.facid
INNER JOIN _university
ON ( _faculty.schid = _university.schid )
WHERE _forum_topics.sub_forum_id IN( 133, 134, 135, 136,
137, 138 )
ORDER BY topic_last_post_time DESC
LIMIT 0, 20)
UNION ALL
(SELECT STRAIGHT_JOIN *,
topic_post_time,
topic_title,
topic_id AS tid,
p.userid AS profile_id,
Concat(first_name, ' ', last_name) AS poster_name,
Concat(first_name, '.', last_name) AS profile_name,
forum_id,
topic_last_post_time,
sch_name_abbrev,
picture_small_url,
profile_pix_upload_path,
profile_pix_upload_path,
LEFT(post_text, 100) AS post_text
FROM _sch_forum_topics s FORCE INDEX(topic_poster)
INNER JOIN _profile p
ON ( p.userid = s.topic_poster )
INNER JOIN _users
ON p.userid = _users.userid
INNER JOIN _class
ON _users.classid = _class.classid
INNER JOIN _unit
ON _class.unitid = _unit.unitid
INNER JOIN _department
ON _unit.deptid = _department.deptid
INNER JOIN _faculty
ON _department.facid = _faculty.facid
INNER JOIN _university
ON _faculty.schid = _university.schid
ORDER BY topic_last_post_time DESC
LIMIT 0, 20)
LIMIT
0, 20