SELECT * FROM certs WHERE id NOT IN (SELECT id_cer FROM revokace);
How do I write the above select statement in CodeIgniter active record?
SELECT * FROM certs WHERE id NOT IN (SELECT id_cer FROM revokace);
How do I write the above select statement in CodeIgniter active record?
I think this code will work. I dont know if this is acceptable query style in CI but it works perfectly in my previous problem. :)
It may be a little late for the original question but for future queries this might help. Best way to achieve this is Get the result of the inner query to an array like this
And then use than array in the following active record clause
Hope this helps
->where()
support passing any string to it and it will use it in the query.You can try using this:
The
,NULL,FALSE
in thewhere()
tells CodeIgniter not to escape the query, which may mess it up.UPDATE: You can also check out the subquery library I wrote.
The functions
_compile_select()
and_reset_select()
are deprecated.Instead use
get_compiled_select()
:Source : http://www.247techblog.com/use-write-sub-queries-codeigniter-active-records-condition-full-explaination/
CodeIgniter Active Records do not currently support sub-queries, However I use the following approach:
_compile_select() and _reset_select() are two undocumented (AFAIK) methods which compile the query and return the sql (without running it) and reset the query.
On the main query the FALSE in the where clause tells codeigniter not to escape the query (or add backticks etc) which would mess up the query. (The NULL is simply because the where clause has an optional second parameter we are not using)
However you should be aware as _compile_select() and _reset_select() are not documented methods it is possible that there functionality (or existence) could change in future releases.