作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在为 laravel 中的一个学校项目制作一个程序,所以我尝试加入两个表:产品和目的地
Product 表包含以下列:id、name
Destinations 表包含以下列:Destinations:id,product_id,destination,quantity,target_person
我需要加入 product_id
和 id
products = DB::table('products')
->leftJoin('destinations','id','=','destinations.product_id ')
->get();
但是当我尝试使用 LEFT JOIN
时,出现以下错误:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in on clause is ambiguous (SQL: select * from
products
inner joindestinations
onid
=destinations
.product_id
)
最佳答案
使用表格引用products.id
products = DB::table('products')
->leftJoin('destinations','products.id','=','destinations.product_id')
->get();
关于php - 违反完整性约束 : How to join two tables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46359730/
我是一名优秀的程序员,十分优秀!