M
M
marq2022-02-28 15:56:04
SQL
marq, 2022-02-28 15:56:04

How to pull data from a table that is not in another laravel table?

Good afternoon, there are two tables
table_1
id | name
1 name_1
2 name_2
3 name_3

table_2
id | another_id | name
1 1 name_1
2 2 name_2
3 2 name_5
4 1 name_3

you need to pull out the name from the table table_1 which is not in table_2 and also so that it does not match the another_id field

return DB::table('table_1')
 ->leftJoin('table_2', 'table_1.name' , '=' , 'table_2.name')
 ->where('table_2.name', null) ->where('table_2. another_id' ,'!= ', $id)
 ->select('table_1.name' )
->get();

did so, if you remove the condition where('table_2. another_id' ,'!= ', $id), then it works, but I also need it to be compared with the "another_id" field with the $id that I pass

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question