我正在尝试运行一个查询,该查询从用户表中选择所有用户并自行加入,因为我想选择创建用户的人。出于某种原因,我在创建者中为 first_name 和 last_name 获得的值与同一用户相同,这不一定是真的。
user_Id, username, first_name, last_name, creator_id
1, ksmith, Kevin, Smith, 1
2, wscott, Will, Scott, 1
3, sjones, Steve, Jones, 1
4, twilliams, Tom, Williams, 4
public function get_with_creator()
{
$this->db->select('users.user_id');
$this->db->select('users.username');
$this->db->select('users.first_name');
$this->db->select('users.last_name');
$this->db->select('users.created_at');
$this->db->select('users.updated_at');
$this->db->select("CONCAT(creator.first_name, ' ', creator.last_name) AS creator_name", FALSE);
$this->db->from($this->_table);
$this->db->join('users AS creator', 'users.user_id = creator.user_id', 'inner');
return $this->db->get()->result();
}