简体   繁体   English

是否可以使用CodeIgniter的查询生成器进行此查询?

[英]Is it possible to make this query using CodeIgniter's Query Builder?

Query: 查询:

select (exists (select 1 from table1 where url = 'fajne-to-jest')) as in_table1,
       (exists (select 1 from table2 where url = 'fajne-to-jest')) as in_table2;

I don't see function like exist. 我看不到功能存在。

I don't think it is possible but maybe I am wrong. 我认为不可能,但也许我错了。

So question is, is it possible to create this complex query with only CodeIgniter's query builder? 因此问题是,是否可以仅使用CodeIgniter的查询生成器来创建此复杂查询?

Probably not as well optimized as your example. 可能没有像您的示例那样优化。 The easiest solution is to not use Querybuilder and write the statement directly for use in query() . 最简单的解决方案是不使用Querybuilder并直接编写要在query()使用的query()

$sql = "select (exists (select 1 from table1 where url = 'fajne-to-jest')) as in_table1,
               (exists (select 1 from table2 where url = 'fajne-to-jest')) as in_table2";
$query = $this->db->query($sql);

Querybuilder (QB) is a great tool but it is often (perhaps more often than not) completely unnecessary. Querybuilder(QB)是一个很棒的工具,但是它经常(也许比不是更多)是完全不必要的。 The primary task of QB is to build a query statement. QB的主要任务是构建查询语句。 Why execute a whole lot of code to create easily written queries? 为什么要执行大量代码来创建易于编写的查询?

QB is great in situations where you need to conditionally alter the query statement. 在需要有条件地更改查询语句的情况下,QB非常有用。 For example adding where clauses, changing sort order etc. 例如添加where子句,更改排序顺序等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM