Welcome Guest, Not a member yet? Register   Sign In
Query multiple table with same field name using active record
#1

[eluser]aryan_[/eluser]
How do I query multiple tables with same field name using active record i.e. using
Code:
$this->db->select('id', 'name');
$this->db->get('t1');
.

I don't like writing long sql statement.
#2

[eluser]bretticus[/eluser]
you mean join tables with the same column names?
#3

[eluser]Asinox[/eluser]
Code:
$this->db->join('table1','table1.id=table2.id')
$this->db->order_by('table2.id','ASC');
$this->db->get('table2')
#4

[eluser]aryan_[/eluser]
Great! How do I access data of same name field? I think in sql query "AS" is used to set the name of columns. How to do using Active record?

Thanks a lot!
#5

[eluser]TheFuzzy0ne[/eluser]
You'll need to use aliases for any fields that match the names of fields in other tables used within your query.
#6

[eluser]rogierb[/eluser]
Just use:
Code:
$this->db->select('some.id as some_id_number');
#7

[eluser]Jevedor[/eluser]
here is a previous thread that i answered this in

http://ellislab.com/forums/viewthread/109045/
#8

[eluser]aryan_[/eluser]
Great help. Thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB