Sub Query in CodeIgniter

By deptz, Mon. November 1, 2010
Categories: PHP related, tutorial
Tags: ,

Few month ago, i posted about sub query in codeigniter here. And today i’ve found another way. It using active record class in codeigniter. For example:

$this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
$query = $this->db->get('mytable');

Just put ‘FALSE’ to second parameter in select() function. $this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

So simple. Isn’t it?:D

2 Responses to “Sub Query in CodeIgniter”

  1. Sub Query dengan CodeIgniter - deptz personal blog Says:

    […] UPDATE: Saya telah memposting cara yang ‘benar’ di SINI […]

  2. Pencerah Says:

    nice info