简体   繁体   English

内部连接错误 - where 子句中的列“id”不明确

[英]Inner join error - Column 'id' in where clause is ambiguous

I had made a product filter, but I had to update.我做了一个产品过滤器,但我必须更新。

Before, the url was passed a slug and an id.之前,url 被传递了一个 slug 和一个 id。 I used this id to get the subcategories and in this table of subcategories a column called 'line_id' is saved.我使用这个 id 来获取子类别,并在这个子类别表中保存了一个名为“line_id”的列。 I took the id passed in the url and looked for what was equal to this line_id.我获取了在 url 中传递的 id,并寻找与此 line_id 相等的内容。 This line_id is for the products page, which has some categories and the subcategories corresponding to each of them.此 line_id 用于产品页面,其中有一些类别以及与每个类别对应的子类别。

Now I have to do it differently, I have to take only one subcategory and select the products corresponding to that subcategory.现在我必须做不同的事情,我必须只取一个子类别和 select 对应于该子类别的产品。

In the products table, the id of each subcategory is already saved.在 products 表中,已经保存了每个子类别的 id。 So I tested it manually, passing an id of a subcategory, but it gives an error when doing the inner join.所以我手动测试了它,传递了一个子类别的 id,但是在进行内部连接时它给出了一个错误。

public function nossas_marcas($slug, $id)
    {
        $menu_path = 'nossas_marcas';
        $category = Categorie::find($id);
        $lines = Line::where('situation', true)->get();

        $ProductsCategories = ProductsCategory::where('id', 3);
        $brandProducts = $ProductsCategories
                            ->join('products', 'products_categories.id', '=', 'products.product_category_id')->get();
        // $brandProducts = $ProductsCategories
        //                     ->join('products', 'products_categories.id', '=', 'products.product_category_id')
        //                     ->take(4)->orderBy(\DB::Raw('rand()'))->get(['products_categories.id', 'products_categories.title as product_category_name', 'products.title as product_title', 'products.id', 'products.ecommerce_link']);

        return view('site.Nossas-marcas.index', compact(['menu_path', 'category', 'lines', 'brandProducts']));
    }

Error错误

Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select * from `products_categories` inner join `products` on `products_categories`.`id` = `products`.`product_category_id` where `id` = 3)

I can't understand the reason for the error, someone explain to me please.我无法理解错误的原因,请有人向我解释。

You should tell him what table do you mean.你应该告诉他你的意思是什么表。 The correct form is products_categories.id , not id .正确的形式是products_categories.id ,而不是id

ProductsCategory::where('id', 3);

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

相关问题 内部联接后,“ where子句中的列'id'不明确”? - “Column 'id' in where clause is ambiguous” after inner joining? INNER JOIN:where子句太含糊 - INNER JOIN : where clause is too ambiguous Yii CDbCriteria错误:where子句中的列“ id”不明确 - Yii CDbCriteria error: Column 'id' in where clause is ambiguous where子句中的列'id_f'是不明确的 - Column 'id_f' in where clause is ambiguous 对于3个表,where子句中的“ id”列含糊不清 - Column 'id' in where clause is ambiguous for 3 tables Codeigniter Laravel - 认证返回“where子句中的列'id'是不明确的”因为GlobalScope中的JOIN - Laravel - Authentication returns “Column 'id' in where clause is ambiguous” because a JOIN in a GlobalScope Codeigniter 3:where子句给出歧义的列错误 - Codeigniter 3: where clause gives an ambiguous column error 带内连接的WHERE子句 - WHERE clause with inner join 在'where'子句中获取列'country_id'是不明确的 - 在cakephp 1.3中的搜索查询中出错 - Getting the column 'country_id' in 'where' clause is ambiguous - error in search query in cakephp 1.3 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM