Welcome Guest, Not a member yet? Register   Sign In
Trying to join two different IDs with AR
#1

[eluser]spmckee[/eluser]
So I have a table called "projects"

Projects
--------------------------------------
| project_id | group_id | company_id |
--------------------------------------
| 1 | 4 | 2 |
--------------------------------------
| 2 | 1 | 2 |
--------------------------------------
| 3 | 0 | 1 |
--------------------------------------

I then have two other tables "groups" and "companies" that I am wanting to grab info from and include in my result. I can grab the info from one table or the other with join but I can't get the info from both tables at then same time.

Any ideas? Thanks.
#2

[eluser]jedd[/eluser]
Why can't you join them both?

What code have you produced so far?
#3

[eluser]spmckee[/eluser]
Here's what I'm using right now for the join part and keep getting: "Not unique table/alias: 'thug_client_groups'"

Code:
$this->db->join('thug_client_groups', 'thug_client_projects.group_id = thug_client_groups.group_id', 'left');
$this->db->join('thug_client_groups', 'thug_client_groups.company_id = thug_client_companies.company_id', 'left');
#4

[eluser]jcavard[/eluser]
You are joining twice the same table, but there is no need.
Try this instead...
Code:
$this->db->select('*');
$this->db->from('thug_client_projects p');
$this->db->join('thug_client_groups g', 'g.group_id = p.group_id', 'left');
$this->db->join('thug_client_companies c', 'c.group_id = p.group_id', 'left');
$this->db->get();

I like your table name... I am a thug too Big Grin
#5

[eluser]spmckee[/eluser]
Sweet!

Had to switch a few of the names but in the end all is well. Good to meet a fellow Thug Wink

Code:
$this->db->join('thug_client_groups g', 'g.group_id = p.group_id', 'left');
$this->db->join('thug_client_companies c', 'c.company_id = p.company_id', 'left');




Theme © iAndrew 2016 - Forum software by © MyBB