[英]complex sql join table
我有4张桌子
chart
, chart_detail
, customer
, produk
像这样
我想运行sql comand以在chart
表中列出数据
我没有问题可以将chart detail
和customer
表加入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
表与produk
表produk
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.