Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter query builder syntax for WHERE EXISTS (subquery)

I'm trying to do a subquery with

$this->db->where(" EXISTS (SELECT * FROM myTable)");

But it doesnt work, the output of this is: myquery + WHERE 'EXISTS (SELECT * FROM myTable);

That quote before the EXISTS makes the query unresolvable!

Does anyone knows how to solve it?

like image 793
Nacho Avatar asked May 01 '26 22:05

Nacho


2 Answers

please remove space before and after EXISTS keyword.that does not display any error.

$this->db->where("EXISTS(SELECT * FROM myTable)");
like image 176
Kack Avatar answered May 03 '26 11:05

Kack


Maybe you could try to set the escape to false by using

$this->db->where(" EXISTS (SELECT * FROM myTable)", null, false);

This is the snippet of where() in DB_active_rec.php

public function where($key, $value = NULL, $escape = TRUE)

like image 21
adesst Avatar answered May 03 '26 11:05

adesst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!