0

I want to write this Sql query using in Laravel 5 Query Builder.

SELECT  * FROM Call WHERE phone_number NOT IN (SELECT phone_number FROM Phone_book)

or(Alternative way)

SELECT * FROM   Call
         LEFT OUTER JOIN Phone_Book
          ON (Call.phone_number = Phone_book.phone_number)

or(Alternative way)

   SELECT * FROM   Call
        WHERE  NOT EXISTS
          (SELECT * FROM   Phone_book
             WHERE  Phone_book.phone_number = Call.phone_number)
               WHERE Phone_book.phone_number IS NULL

I tried several ways but i couldn't write a query.is there any way to use Sql syntax with in query builder or how write this same query using Query Builder? please , help me.

(I tested above 3 query out put is same . I want to write these one query using Query Builder syntax)

6
  • 1
    Which query (not "quarry") do you actually want to build using Laravel? Have you tested any of these queries? Commented Sep 17, 2015 at 0:55
  • Thank you @TimBiegeleisen I edited question. Commented Sep 17, 2015 at 0:58
  • These queries are NOT the same. Commented Sep 17, 2015 at 1:03
  • Attempted code using query builder? Commented Sep 17, 2015 at 1:04
  • @aldrin27 I attempted [laravel.com/docs/5.0/queries#joins] .but i couldn't take expected results. :-( Commented Sep 17, 2015 at 1:09

1 Answer 1

2
DB::table('Call')->whereNotIn('phone_number', function($query)
{
    $query->select('phone_number')
        ->from('Phone_book');
})
->get();

This code is absolutely same with the first sql query u posted.

Sign up to request clarification or add additional context in comments.

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.