簡體   English   中英

復雜的SQL聯接表

[英]complex sql join table

我有4張桌子
chartchart_detailcustomerproduk
像這樣

在此處輸入圖片說明 在此處輸入圖片說明

在此處輸入圖片說明 在此處輸入圖片說明

我想運行sql comand以在chart表中列出數據

我沒有問題可以將chart detailcustomer表加入cart表,因為

chart.id = chart_detail.id_chart
chart.id_customer = customer.id

DB::table('chart')
    ->join('customer', 'chart.id_customer', '=', 'customer.id')
    ->join('chart_detail', 'chart.id', '=', 'chart_detail.id_chart')->get(); 

但我有問題無法訪問nama_produk
(在chart_detail表中只有id_produk )...所以我需要將chart表與produkproduk

DB::table('chart')
    ->join('customer', 'chart.id_customer', '=', 'customer.id')
    ->join('produk', 'produk.id', '=', 'chart_detail.id_produk')
    ->join('chart_detail', 'chart.id', '=', 'chart_detail.id_chart')->get(); 

但我得到這樣的錯誤

Column not found: 1054 Unknown column 'chart_detail.id_produk' in 'on clause'

因為在chart表中沒有可用的id_produk
chart_detail表中可用的id_produk

我想知道如何解決

您的連接混亂,因此出現有關未知列的錯誤。 嘗試以下代碼:

DB::table('chart')
    ->join('customer', 'chart.id_customer', '=', 'customer.id')
    ->join('chart_detail', 'chart.id', '=', 'chart_detail.id_chart')
    ->join('produk', 'produk.id', '=', 'chart_detail.id_produk')->get(); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM