gpt4 book ai didi

php - 违反完整性约束 : How to join two tables

转载 作者:可可西里 更新时间:2023-11-01 07:24:42 24 4
gpt4 key购买 nike

我正在为 laravel 中的一个学校项目制作一个程序,所以我尝试加入两个表:产品和目的地

Product 表包含以下列:id、name

Destinations 表包含以下列:Destinations:id,product_id,destination,quantity,target_person

我需要加入 product_idid

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 join destinations on id = 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com