日期:2014-05-16  浏览次数:20804 次

论坛显示置顶贴的SQL


thread_table:

id(int)   ID
title(varchar)   标题
class_id(int)   分类、
...  
in_top(tinyint)   置顶

如果要在第一页优先把置顶的主题帖子给搜索出来,(假设每页显20个主题帖子,当有5个置顶帖子时,要得到5个is_top为1的,和15个is_top为0的)那么要需要查表两次吗?

------解决方案--------------------
不需要。

select * from thread_table where is_top = 1 limit 5 union all select * from thread_table where is_top = 0 limit 15;