我有一個表TblOrders,它們分別具有兩個字段,如FldOrderStatusId和FldInstrumentID作爲來自表TblOrderStatus和TblInstrumentMasters的表中的外鍵。這是可能的左表連接。代碼如下:應用左連接從多個表中使用外鍵提取數據
$find_filled_orders = $this->UserOrder->query(
"Select distinct(FldOrderNumber) from TblOrders where FldOrderStatusId =12 ");
$res_order="";
$i=0;
foreach($find_filled_orders as $order_arr)
{
if($i!=0)
{
$res_order.=",";
}
$res_order.="'".$order_arr['TblOrders']['FldOrderNumber']."'";
$i++;
}
$where_not_in="";
if($i>=1)
{
$where_not_in = "AND FldOrderNumber NOT IN (".$res_order.")";
}
//debugbreak();
$current_order = $this->UserOrder->query(
"Select * from TblOrders where 1 ".$where_not_in.
" group by FldOrderNumber order by FldSlNo desc");
我想在最後一行查詢中應用左連接。請大家幫我解決。 在此先感謝。
謝謝.... acctually我改變字段名,而不是蛋糕的命名約定.. –
這裏是查詢:SELECT * FROM TblOrders LEFT JOIN TblInstrumentMasters ON TblOrders.FldInstrumentID = TblInstrumentMasters.FldInstrumentID LEFT JOIN TblOrderStatus ON TblOrders .FldOrderStatusId = TblOrderStatus.FldId其中1「。$ where_not_in。」由FldOrderNumber按FldSlNo desc命令排序 –