Integrity constraint violation: how to join two tables

I am making a program for a school project in laravel, so I am trying to join two tables: products and directions

The Product table has columns: id, name

The Target table has the following columns: Directions: id, product_id, destination, quantity, target_person

and i need to join product_idandid

products = DB::table('products')
    ->leftJoin('destinations','id','=','destinations.product_id ')
    ->get();

but when I try to use LEFT JOIN, I get the following error:

SQLSTATE [23000]: Violation of integrity constraint: 1052 The column "id" in on is ambiguous (SQL: select * from productsinternal connection destinationson id= destinations. product_id)

+4
source share
2 answers

products.id

products = DB::table('products')
    ->leftJoin('destinations','products.id','=','destinations.product_id')
    ->get();
+4

, , . :

products = DB::table('products')
->leftJoin('destinations','products.id','=','destinations.product_id')

->get();
+2

Source: https://habr.com/ru/post/1686184/


All Articles