Welcome Guest, Not a member yet? Register   Sign In
Having some problems with Active Record query
#1

[eluser]blitzneo[/eluser]
I have this query, and I really don't know how to change it to AR.

Any time I want to run an 'inner join' query, it adds additional fields I don't need.. but that's because I am sure I am doing something wrong.

This is the query:

$q = 'SELECT a.id as j, a.value as k
FROM a
WHERE a.id
IN (
SELECT b.aid
FROM b
WHERE b.cid = 1
)';

Any tips ? Thanks in advance!


EDIT:

I just found it -.-

$q = $this->db->select('
a.id as j,
a.value as k');
$this->db->from('a');
$this->db->where_in('a.id', 'SELECT b.aid FROM b WHERE b.cid = 1');

Anyway, can it be improved ?
Thanks ^^
#2

[eluser]Atharva[/eluser]
Using joins instead of sub-query will improve the execution time.




Theme © iAndrew 2016 - Forum software by © MyBB