Welcome Guest, Not a member yet? Register   Sign In
Alias, how?
#1

[eluser]Asinox[/eluser]
Hi, im trying to make a JOIN but i hav a field with the same name in both tables, how i ll make a ALIAS for 1 field?
Code:
function listar_subcategorias(){
        $this->db->select('*');
        $this->db->from('subcategories');
        $this->db->join('categories','categories_id=subcategories.category_id');
        $query = $this->db->get();
        return $query->row_result();
}

Thanks
#2

[eluser]Asinox[/eluser]
thanks

i did it

Code:
function listar_subcategorias(){
        $this->db->select('subcat_id,category_id,subcategoria, subcategories.pub as publico FROM subcategories');
//        $this->db->from('subcategories');
        $this->db->join('categories','categories_id=subcategories.category_id');
        $query = $this->db->get();
        return $query->result();
    }
#3

[eluser]meigwilym[/eluser]
Do you mean an alias for table names? This is what I think you need (personally, I like to write out my SQL queries, so I'll do the same here).

Code:
$sql = "SELECT * FROM subcategories AS sc
        INNER JOIN categories AS c
        ON sc.category_id = c.category_id";

$query = $this->db->query($sql);
return $query->row_result();

Bear in mind that this query will return everything, so you may need a WHERE clause too, but that depends on your needs, of course.

Best,

Mei
#4

[eluser]Asinox[/eluser]
Thanks u Smile




Theme © iAndrew 2016 - Forum software by © MyBB