码迷,mamicode.com
首页 > Windows程序 > 详细

Phalapi 中Union和Union All的用法

时间:2015-11-23 18:30:26      阅读:412      评论:0      收藏:0      [点我收藏+]

标签:

有时候在进行数据库查询的时候会用到union查询,但是查询的时候会发现两个limit只有一个是有效的,如下查询

select * from table where status = 0 limit 10
union
select * from table where status = 1 limit 30

这样的语句实际的查询效果是这样的,如下:

(select * from table where status = 0 limit 10)
union
(select * from table where status = 1) limit 20

如果想让limit有效,必须要把limit放到括号当中才行。

Phalapi中notorm的写法是,如下:

  public function getSogouGuojiList() {
        $result = array();
        $query = DI()->notorm->table->select(‘id,title,content‘)
                ->where(‘status =?‘, 0)->order(‘id desc‘)
                ->limit(10);
        $query2 = DI()->notorm->table->select(‘id,title,content‘)
                ->where(‘status =?‘, 0)->order(‘id desc‘)
                ->limit(20);
        foreach ($query->union($query2) as $row) {
            $result[] = $row;
        }
        return $result;
   }

注:如果有不对的地方还请多多指教。

 

Phalapi 中Union和Union All的用法

标签:

原文地址:http://www.cnblogs.com/kekeer/p/4989107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!