[英]SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5.5
I just don't know what's wrong with my code and why it produces this error 我只是不知道我的代码有什么问题以及它为什么会产生这个错误
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous (SQL: select * from
processes
inner joinbags
onprocesses
.bag_id
=bags
.id
wherebags
.type
= Recyclable and date(processes
.created_at
) = 2018-09-18 00:00:00 order bycreated_at
desc limit 1) and here's my codeSQLSTATE [23000]:完整性约束违规:为了条款1052列'created_at'不明确(SQL:SELECT * FROM
processes
内加入bags
上processes
。bag_id
=bags
。id
,其中bags
。type
=可回收和日期(processes
。created_at
) = 2018-09-18 00:00:00按created_at
desc limit 1)排序,这是我的代码
$bag = Bagcollect::join('bags', 'bagcollects.bag_id', '=', 'bags.id')
->select('bags.type')
->where('bagcollects.bag_id', $request->input('bag_id'))
->first();
//this query produce error
$processexist = Process::join('bags', 'processes.bag_id', '=', 'bags.id')
->where('bags.type', $bag->type)
->whereDate('processes.created_at', Carbon::today())
->latest()
->first();
You'll need to specify, in latest()
the full column. 您需要在
latest()
指定完整列。 latest('process.created_at')
or instead of using latest()
use a custom orderBy. latest('process.created_at')
或代替使用latest()
使用自定义orderBy。
Thats because you are querying the 'created_at' column from two tables. 那是因为你从两个表中查询'created_at'列。 You have to specify wich colums you need, for example:
您必须指定所需的所有列,例如:
$processexist = Process::join('bags', 'processes.bag_id', '=', 'bags.id')
->select('bags.column1', 'bags.columns2')
->where('bags.type', $bag->type)
->whereDate('processes.created_at', Carbon::today())
->latest()
->first();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.