Welcome Guest, Not a member yet? Register   Sign In
Active Record - where_in
#1

[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.
#2

[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).
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB