2012-01-24 8 views
0

myテーブル(構造体、サーフェス)には2つのインデックス行 "planet_id"と "tile_id"があります。私はそれらに参加したいが、私はSQLエラー: "列 'planet_id' where句であいまいです"を取得します。あなたは2つの表にplanet_idを持っているので、あなたはあなたにwhereを適用しているかを選択する必要がありますCodeigniterアクティブレコード "JOIN" 2つのインデックス

Error Number: 1052 

Column 'planet_id' in where clause is ambiguous 

SELECT * FROM (`structures`) JOIN `surface` ON `structures`.`planet_id`=`surface`.`planet_id` AND structures.tile_id=surface.tile_id WHERE `planet_id` = '13247' 

答えて

2

$this->db ->select('*') 
    ->from('structures') 
    ->join('surface', 'structures.planet_id=surface.planet_id AND structures.tile_id=surface.tile_id') 
    ->where('planet_id', $p->planet_id); 

$query = $this->db->get(); 

はにつながります。あなたの参加が同じになるように、両方のplanet_id年代が必要ですが、whereはそれを知らない、と具体的な指示を必要とするので、それは愚かに見えるかもしれません

$this->db->select('*') 
    ->from('structures') 
    ->join('surface', 'structures.planet_id=surface.planet_id AND structures.tile_id=surface.tile_id') 
    ->where('structures.planet_id', $p->planet_id); 

$query = $this->db->get(); 

ので、これを試してみてください。

+0

ありがとうございました!あなたは私の日を救った:) – Sserpyc

関連する問題