0

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']);
    }
4
  • 1
    Please add some sample data to your question. Show input and output. Commented Oct 1, 2018 at 6:51
  • your question is quite confusing , please add exact name for myColumn ? Commented Oct 1, 2018 at 6:58
  • Instead of !empty($request->get('typ') try to use $request->has('typ') Commented Oct 1, 2018 at 7:01
  • Your current query makes no sense. Please add sample data to your question which explains it. Sample input and output usually works best. Commented Oct 1, 2018 at 7:04

4 Answers 4

1

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');
Sign up to request clarification or add additional context in comments.

2 Comments

You have a right, but query in question have two where
just to mention here , Both code are not same, wetting two where function are to apply AND and using whereIn is for OR
1

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

1 Comment

you can use whereIn method of laravel
0

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']);

5 Comments

no i have more values in my column :) so AND is right here :)
please share your columns value sample ?
is your myColumn different ?
if(!empty($request->get('typ'))){ $angebots->whereIn('typ', [$typ, 'Jeden']); }
@MonaMuhr : if whereIn worked for you then you were needed OR not AND
0

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

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

1 Comment

How can a given column in a single record have two different values at the same time?

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.