简体   繁体   中英

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?

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() .

$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. The primary task of QB is to build a query statement. 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. For example adding where clauses, changing sort order etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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