union后统计 union后排序分页

union统计

$sql = "select count(*) as total from((select t.id  from arctype t,article a  where t.iszt>0 and t.keyarr!='' and a.id=t.keyarr and t.iscap=1 $addCondition)union(select t.id from article a,arctype t where a.typeid=t.id and t.iszt=3 and t.iscap=1 $yxscCondition)) as a";

注意:刚开始()后没加 as a,执行后报错,提示需要添加别名,union结果作为表查询时必须加别名as table


union排序分页

$sql = "(select a.litpic as icon,a.id,a.pubdate,a.shorttitle as title,t.keyarr,t.domainname,a.typeid,t.iszt from article a,arctype t where t.iszt>0 and t.keyarr!='' and a.id=t.keyarr and t.iscap=1 $addCondition) union (select a.icon,a.id,a.pubdate,a.title,t.keyarr,t.domainname,a.typeid,t.iszt from article a,arctype t where a.typeid=t.id and t.iszt=3 and t.iscap=1 $yxscCondition) order by pubdate desc limit $start,$pageSize";

注:像表一样操作就可以了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值