简体   繁体   English

SQLSTATE[23000]:违反完整性约束:1052 列 'created_at' 在 where 子句中不明确

[英]SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous

laravel join tabel search. laravel 加入表格搜索。

error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous (SQL: select tbl_die_management_categories .*, tbl_die_management_subcategories . id as t2 , tbl_die_management_subcategories . die_weight from tbl_die_management_categories inner join tbl_die_management_subcategories on tbl_die_management_categories . id = tbl_die_management_subcategories . die_categories_id where created_at like %2022-11-17%) error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous (SQL: select tbl_die_management_categories .*, tbl_die_management_subcategories . id as t2 , tbl_die_management_subcategories . die_weight from tbl_die_management_categories inner join tbl_die_management_subcategories on tbl_die_management_categories . id = tbl_die_management_subcategories . die_categories_id where created_at like %2022-11-17%)

 public function diemanagement(Request $request)
    {
        $DieManagementCategories = DB::table('tbl_die_management_categories');
        if($request->keyword != null){
           $DieManagementCategories = $DieManagementCategories->where('created_at','like','%'.$request->keyword.'%');
        }
        $DieManagementCategories = $DieManagementCategories->select('tbl_die_management_categories.*','tbl_die_management_subcategories.id as t2','tbl_die_management_subcategories.die_weight')
        ->join('tbl_die_management_subcategories','tbl_die_management_categories.id','=','tbl_die_management_subcategories.die_categories_id')
        ->get();
        // dd(json_encode($DieManagementCategories));
        $DieManagementCategories = DieManagementCategories::with('subcategories')->get();
  
        return view('admin.diemanagement.diemanagement',['DieManagementCategories'=>$DieManagementCategories]);
        
    }

you have two tables to select from in your query您的查询中有两个表 select

tbl_die_management_categories, tbl_die_management_subcategories

both with created_at column... in your where clause you should specify on what created_at column the condition will be applied.... just set the table name before column name to do that:两者都带有created_at列...在您的where子句中,您应该在将应用条件的created_at列上指定....只需在列名之前设置表名即可:

 if($request->keyword != null){
           $DieManagementCategories = $DieManagementCategories->where('tbl_die_management_categories.created_at','like','%'.$request->keyword.'%');
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 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 SQLSTATE [23000]:完整性约束违规:1052 列“created_at”在 order 子句中不明确 Laravel 8 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 8 SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where 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子句中的列'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” MySQL错误:冲突:1052 where子句不明确的列'created_at' - Mysql error: violation: 1052 Column 'created_at' in where clause is ambiguous' 违反完整性约束:1052列和where子句不明确 - Integrity constraint violation: 1052 Column and in where clause is ambiguous 完整性约束违规:1052 where子句中的列'id'不明确 - Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM