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