CodeIgniter Forums
Active Record - where_in - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Active Record - where_in (/showthread.php?tid=35825)



Active Record - where_in - El Forum - 11-12-2010

[eluser]Unknown[/eluser]
I have a complication query

Code:
SELECT *
FROM news INNER JOIN categories ON news.CateID = categories.CateID
WHERE Languages = 2
    AND isPublished = 1
    AND (news.CateID ,CreatedDate) in (SELECT CateID, max(CreatedDate) FROM news WHERE Languages = 2 GROUP BY CateID)
GROUP BY news.CateID
ORDER BY news.CateID ASC, CreatedDate DESC
LIMIT 6 OFFSET 0

I couldn't transform it to "Active record query"
I tried to use where_in('(news.CateID ,CreatedDate)', '(SELECT CateID, max(CreatedDate) FROM news WHERE Languages = 2'); but couldn't successful

Plz help me !

Cheers.


Active Record - where_in - El Forum - 11-12-2010

[eluser]Bart Mebane[/eluser]
If the sql is complex enough that it's not obvious how to do it with active record, you can just use your own sql instead, like:
Code:
$query = $this->db->query($sql);
If you have input data in your query, you need to be careful to escape it, since active record does that automatically. (For example, see Database Library > Queries > Query Bindings in the User Guide).


Active Record - where_in - El Forum - 11-14-2010

[eluser]Unknown[/eluser]
Tks alot Bart Mebane Smile