[eluser]frist44[/eluser]
With query problems, I generally enable the profiler ($this->output->enable_profiler(TRUE)
and look at the query at the bottom. Copy/paste into a query manager and see the output. I screw around with the query until it produces the correct results and then modify the code to produce that query. That may seem trial by fire, but it works for me, maybe or may not help in your case.
Seeing what the actual generated SQL is seems very valuable to me.