使用此查询,它会在第一页显示所有featured=1
条记录,然后在第二页显示所有记录。
$sql = "(select * from `property` where (`city`='33') AND (`featured` = '1') LIMIT 5)
UNION ALL (select * from `property` where (`city`='33') AND (`featured` = '0') LIMIT 5) LIMIT 0,10 ";
我想显示featured=1
的5条记录和featured=0
的5条记录我想到的最后一个限制存在问题,因为当我删除最后的限制它显示我的所有记录所有页面都featured=1
,但内部限制出现问题。
echo $sql = "(select * from `property` where (`city`='33') AND (`featured` = '1') LIMIT 5)
UNION ALL (select * from `property` where (`city`='33') AND (`featured` = '0') LIMIT 5) ";
答案 0 :(得分:1)
如果您想获得featured = '1'
的5条记录并将其与5条featured = '0'
记录合并,请执行以下操作:
(select * from `property` where (`city`='33') AND (`featured` = '1') LIMIT 5)
UNION ALL
(select * from `property` where (`city`='33') AND (`featured` = '0') LIMIT 5)