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

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")

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


Theme © iAndrew 2016 - Forum software by © MyBB