Welcome Guest, Not a member yet? Register   Sign In
Active Record Class
#1

[eluser]MEM[/eluser]
Is it possible to use UNION trough Active Record Class ?


What I'm trying to create using Active Record Class is:

Code:
SELECT p.id_prod, p.id_cat, p.nome_prod
FROM produto p
INNER JOIN categoria c ON c.id_cat = p.id_cat
INNER JOIN categoria c2 ON c.parent_id_cat = c2.id_cat
WHERE c2.parent_id_cat = 1
UNION
SELECT p.id_prod, p.id_cat, p.nome_prod
FROM produto p
INNER JOIN categoria c ON c.id_cat = p.id_cat
WHERE c.parent_id_cat = 1 OR p.id_cat = 1

Can I have your experiment eyes on this?


Thanks a lot,
Márcio
#2

[eluser]MEM[/eluser]
I end up "solving it" like this:

Code:
public function getProdutosByCategoria($id_cat)
{
        
$strSQL = 'SELECT p.id_prod, p.id_cat, p.nome_prod
FROM produto p
INNER JOIN categoria c ON c.id_cat = p.id_cat
INNER JOIN categoria c2 ON c.parent_id_cat = c2.id_cat
WHERE c2.parent_id_cat =' .$id_cat. '
UNION
SELECT p.id_prod, p.id_cat, p.nome_prod
FROM produto p
INNER JOIN categoria c ON c.id_cat = p.id_cat
WHERE c.parent_id_cat =' .$id_cat. ' OR p.id_cat = ' .$id_cat;
            
$query = $this->db->query($strSQL);        
(...)




Theme © iAndrew 2016 - Forum software by © MyBB