[英]Codeigniter Active Record “JOIN” with two Index
我的表(結構,表面)有兩個Index-Rows,“planet_id”和“tile_id”。 我想加入他們,但是我得到了一個SQL-Error:“where'leral'id'在where子句中是不明確的”。
$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();
導致:
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'
由於您在兩個表中都有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();
這可能看起來很愚蠢,因為你的連接要求planet_id
都是相同的,但是where
不知道,並需要特定的指令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.