Welcome Guest, Not a member yet? Register   Sign In
Multiple db join on same table
#4

[eluser]aquary[/eluser]
I understand that it's not in separate tables, but my answer was that "you have to join the users table 2 times". I also have that kind of query for my webboard topics & replies, which looks like....

Code:
$this->db->select("topics.*, topic_creater.username as creater_name, topic_updater.username as updater_name")
->join("users topic_creater", "topics.topic_userid=topic_creator.user_id")
->join("users topic_updater", "topics.topic_modified_userid=topic_updater.user_id")
->get("topics");

Please note that I join on the same "users" table 2 times, but aliased it differently for selecting theirs data.


Messages In This Thread
Multiple db join on same table - by El Forum - 06-21-2011, 02:13 AM
Multiple db join on same table - by El Forum - 06-21-2011, 02:51 AM
Multiple db join on same table - by El Forum - 06-21-2011, 03:01 AM
Multiple db join on same table - by El Forum - 06-21-2011, 03:09 AM
Multiple db join on same table - by El Forum - 06-21-2011, 03:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB