CodeIgniter Subquery with Alias
CI ActiveRecord does not support subquery out of the box.
NITCompass wrote this awesome library for the subquery support, which you can download from here:
The only problem in this library is, it does NOT support aliases.
We tweaked this library and added support for the aliases. Please download this changed subquery file from our website and use it in the exact same manner as you would have used the original library and it would start supporting aliases.
Changes in the file are commented with “Changed by Tudip to support Alias” (line # 86 & 104).