2016-03-30 32 views
1

我需要加入相同的表使用不同的密鑰,加入表的mysql有兩個不同的密鑰

我使用笨,所以下面是語法加入它,

$this->db->join('sc_countries', 'sc_countries.country_id = sc_users.user_country', 'LEFT'); 
    $this->db->join('sc_countries', 'sc_countries.country_id = sc_agents.agent_country', 'LEFT'); 

,當我試圖加入這個它拋出錯誤

Not unique table/alias: 'sc_countries' 

我該如何做這種類型的連接?

謝謝advnace,因爲相同的表連接兩次

回答

3

SQL解釋沒有找到確切表。

它是衝突的。爲避免衝突,請使用別名替換表格:

$this->db->join('sc_countries AS C', 'C.country_id = sc_users.user_country', 'LEFT'); 
$this->db->join('sc_countries AS D', 'D.country_id = sc_agents.agent_country', 'LEFT');