Neha
Neha

Reputation: 2261

Laravel where query for getting record if the difference of two fields is not 0

I need to get record only if subtraction of two fields is not zero.

$list = InspectionCertificate::where('amount' - 'billed_amount' != 0)

Thanks in advance.

Upvotes: 0

Views: 68

Answers (3)

Lakhwinder Singh
Lakhwinder Singh

Reputation: 5582

Here is the sample code for that with Eloquent Model

$list = InspectionCertificate::whereRaw('(amount - billed_amount) > 0')->get();

You can use whereRaw to pass raw query in Query Builder.

Upvotes: 2

nakov
nakov

Reputation: 14268

Sharing more info you will get a better answer, but here is a way using the query builder:

\DB::table('table_name')
    ->havingRaw('(column1 - column2) != 0')
    ->get();

Upvotes: 1

Arulkumar
Arulkumar

Reputation: 13237

Using Not Equal operator, you can able to do.

Sample query:

SELECT *
FROM TableName    
WHERE (ColumnName1 - ColumnName2) != 0

Upvotes: 0

Related Questions