2013-03-09 52 views
0

我有查詢:如何僅從相關表中獲取特定列?

$sql = new Sql($this->tableGateway->getAdapter()); 
$select = $sql->select(); 

$select->from('table_1') 
    ->join('table_2', 'table_2_se_id = table_2.se_id 
         and table_2_table_3_id = table_2.table_3_id', 
         '*', 'LEFT') 
    ->join('table_3', 'table_2_table_3_id=table_3.id', '*', 'LEFT') 
    ->join('table_4', 'table_4_id=table_4.id', '*', 'LEFT'); 

如何獲得只有一列(例如 '名')從TABLE_4?

回答

2

join()的第三個參數是指定列的位置,此時您選擇全部*。該參數可以是代表一列或多列的一個陣列的字符串,所以下面應該工作

->join('table_4', 'table_4_id=table_4.id', 'name', 'LEFT'); 
+0

是的,但我也得從TABLE_3,TABLE_1和TABLE_2等領域... – Nips 2013-03-10 09:59:20

+2

嘗試更換'」 *''在'joins'中加入'array()',你不想從中選擇列 – Crisp 2013-03-10 10:15:32

相關問題