2

Im 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?

Thanks!

Nacho
  • 2,057
  • 2
  • 23
  • 32
  • 2
    [this](http://stackoverflow.com/questions/6047149/subquery-in-codeigniter-active-record) might shed some light – Kevin Aug 29 '14 at 03:38

3 Answers3

6

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

$this->db->where("EXISTS(SELECT * FROM myTable)");
Kack
  • 86
  • 2
3

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)

adesst
  • 297
  • 3
  • 7
1

Just try this.

Instead of using 'where' clause, please write down the complete query string & execute the query using $this->db->query();

    $qry_string= $yourquery . "WHERE EXISTS (SELECT * FROM myTable)";
    $this->db->query($qry_string);
g4GG
  • 11
  • 5