Welcome Guest, Not a member yet? Register   Sign In
Create subquery in WHERE
#1

I have subquery like this its working, how i can rewrite with active record?

$builder->where("(SELECT SUM(sum) FROM payments WHERE visit = v.id) > 0");


Like this

$SubQuery = $this->db->table('payments ')->select('SUM(sum)')->where('visit = v.id');


$MainQuery = $this->db->table('visits')->where("$SubQuery > 0")
Reply
#2

Your $SubQuery return not the SQL statement. It returns the result.
You have to use the "getCompiledSelect()" Method for $SubQuery....

https://codeigniter.com/user_guide/datab...iledselect
Reply




Theme © iAndrew 2016 - Forum software by © MyBB