我如何编写查询以获得 3sname的type=0另一个 3stype=1和 3stype=2总共 9 name。我只输出type=0. 发誓UNION ALL。
Select forum_thread.name, forum_thread.updatedat, forum_thread.threadtype
From forum_thread, business
Where business.id = 1 AND forum_thread.threadtype=0
Order by forum_thread.threadtype, forum_thread.updatedat desc limit 3
UNION ALL
Select forum_thread.name, forum_thread.updatedat, forum_thread.threadtype
From forum_thread, business
Where business.id = 1 AND forum_thread.threadtype=1
Order by forum_thread.threadtype, forum_thread.updatedat desc limit 3
UNION ALL
Select forum_thread.name, forum_thread.updatedat, forum_thread.threadtype
From forum_thread, business
Where business.id = 1 AND forum_thread.threadtype=2
Order by forum_thread.threadtype, forum_thread.updatedat desc limit 3
如果由于某种原因这比你的 3-union 解决方案慢,只需将子查询括在括号中
(select ... limit 3) UNION ALL (select ... limit 3)