繁体   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