Codeigniter subquery exists

ⅰ亾dé卋堺 提交于 2019-12-24 13:02:34

问题


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!


回答1:


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

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



回答2:


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)




回答3:


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);


来源:https://stackoverflow.com/questions/25561306/codeigniter-subquery-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!