MonaMuhr
MonaMuhr

Reputation: 185

How can i use the AND Operator in Laravel in my query

How do I get this syntax in Laravel?

SELECT *
FROM myTable
WHERE myColumn = 'A' 
AND myColumn = 'B'; 

I know this syntax in Laravel:

DB::table('myTable')->where('myColumn', 'A');

And I tried something like this:

DB::table('myTable')->where('myColumn', 'A' AND 'B');

or

DB::table('myTable')->where('myColumn', 'A' AND 'myColumn' 'B');

but nothing works

So how can I use the AND operator in Laravel? Or is this not possible?

Thank You!

I got it now:

if(!empty($request->get('typ'))){
     $angebots->whereIn('typ', [$typ, 'Jeden']);
    }

Upvotes: 0

Views: 60

Answers (4)

Ram Aravind
Ram Aravind

Reputation: 1

If you use multiple where conditions, automatically it will take as AND operator.

DB::table('myTable')->where('myColumn', 'A')->where('myColumn','B')->get();

Upvotes: 0

Egretos
Egretos

Reputation: 1175

You can use whereIn. At your case it have to work.

DB::table('myTable')->whereIn('myColumn', ['A', 'B'])

And if you are going to use where

DB::table('myTable')
        ->where('myColumn', 'A')
        ->orWhere('myColumn', 'B');

Upvotes: 1

Sunil kumawat
Sunil kumawat

Reputation: 804

you can do this

 DB::table('myTable')->where('myColumn_1', 'A')->where('myColumn_1' 'B')->get();

If values are multiple and column name is same then use whereIn()

 DB::table('myTable')->whereIn('myColumn', ['A','B'])->get(); //pass array of data

Upvotes: 1

Niklesh Raut
Niklesh Raut

Reputation: 34914

How same column have two column, I guess you should use OR here not AND

and for this laravel have whereIn function

DB::table('myTable')->whereIn('myColumn', ['A','B']);

Upvotes: 0

Related Questions