Phalapi 中Union和Union All的用法
2017-11-28 00:00
148 查看
有时候在进行数据库查询的时候会用到union查询,但是查询的时候会发现两个limit只有一个是有效的,如下查询
这样的语句实际的查询效果是这样的,如下:
如果想让limit有效,必须要把limit放到括号当中才行。
Phalapi中notorm的写法是,如下:
打印sql语句,链接后面跟上&__sql__=1就可以了。
完整的链接是:http://localhost/PhalApi/Public/?service=Default.index&__sql__=1(根据自己的配置环境修改成自己的url地址)
注:如果有不对的地方还请多多指教。
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; }
打印sql语句,链接后面跟上&__sql__=1就可以了。
完整的链接是:http://localhost/PhalApi/Public/?service=Default.index&__sql__=1(根据自己的配置环境修改成自己的url地址)
注:如果有不对的地方还请多多指教。
相关文章推荐
- UNION和UNION ALL的用法区别
- 数据库union 和 union all的用法
- ORACLE 函数minus、intersect、union、union all 用法
- Union,Union all用法及区别
- SQL中Union和Union All的用法
- Oracle中 union 和 union all 的用法和区别
- sql Union和Union All用法及区别(union where条件使用)
- SAP HANA SQL语句UNION 和 UNION ALL的用法
- union, union all 的用法
- union与union all的用法
- SQL语句UNION与UNION ALL的用法
- MYSQL用法(三) UNION,UNION ALL 用法
- SQL Server 排序函数 ROW_NUMBER、RANK、DENSE_RANK、INTERSECT、UNION、UNION ALL 用法总结
- sql中exists,Intersect ,union 与union All的用法
- oracle中union 和union all的用法
- mysql中union、union all的用法实例
- union,union all用法及区别
- Oracle中的Union、Union All、Intersect、Minus 使用用法区别
- Union和Union ALL的用法
- union、union all的用法和区别