简体   繁体   English

SQLSTATE [23000]:完整性约束违规:1052 order order中的'created_at'列不明确Laravel 5.5

[英]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 join bags on processes . bag_id = bags . id where bags . type = Recyclable and date( processes . created_at ) = 2018-09-18 00:00:00 order by created_at desc limit 1) and here's my code SQLSTATE [23000]:完整性约束违规:为了条款1052列'created_at'不明确(SQL:SELECT * FROM processes内加入bagsprocessesbag_id = bagsid ,其中bagstype =可回收和日期( processescreated_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.

相关问题 SQLSTATE [23000]:完整性约束违规:1052 列“created_at”在 order 子句中不明确 Laravel 8 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 8 Yii2 GridView:SQLSTATE[23000]:违反完整性约束:1052 order 子句中的列“id”不明确 - Yii2 GridView: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous Laravel Eloquent SQLSTATE[23000]:违反完整性约束:1052 列...在 where 子句中不明确 - Laravel Eloquent SQLSTATE[23000]: Integrity constraint violation: 1052 Column ... in where clause is ambiguous Laravel 6 错误:SQLSTATE[23000]:违反完整性约束:1052 where 子句中的列“id_perusahaan”不明确 - Laravel 6 Error : SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_perusahaan' in where clause is ambiguous SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 where子句中的列'status'不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 where子句中的列'NRP'不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'NRP' in where clause is ambiguous Magento问题与外部mod“违反完整性约束:1052 where子句不明确的列'created_at'” - Magento issue with external mod “Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous” 违反完整性约束:1052 order子句中的“位置”列不明确 - Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous Laravel 完整性约束违规:1052 列 'id' in where 子句不明确 - Laravel Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM