0

I have no idea how to write it in Laravel Query Builder. Here's the SQL query:

select l.id, l.title, is1.similarity
FROM l
left join is1 on (l.id = is1.listing_id1 and is1.listing_id2 = 225678) or (l.id = is1.listing_id2 and is1.listing_id1 = 225678)

2 Answers 2

2

If I simply translate your SQL query to Laravel Query Builder query It would look like this.

DB::table('l')->select('l.id', 'l.title', 'is1.similarity')
 ->leftJoin('is1', function ($leftJoin) { 
    $leftJoin->on('l.id', '=', 'is1.listing_id1')->where('is1.listing_id2', '=', '225678')
     ->orOn('l.id','=',  'is1.listing_id2')->where('is1.listing_id1','=', '225678'); })
->get();
Sign up to request clarification or add additional context in comments.

Comments

0

I guess, it would be something like this:

DB::table('l')
->('l.id', 'l.title', 'is1.similarity')
 ->join('is1', function ($join) {
    $join->on('l.id', '=', 'is1.listing_id1') ->where('is1.listing_id2', '=', '225678')
         ->orOn('l.id','=',  'is1.listing_id2')->where('is1.listing_id1', '=', '225678');
 })->get();

Don't forget to import this:

use Illuminate\Support\Facades\DB;

More information can be find here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.