Laravel 9 whereIn / whereNotIn / orWhereIn / orWhereNotIn

Websolutionstuff | Oct-17-2022 | Categories : Laravel

In this article, we will see Laravel 9 whereIn / whereNotIn / orWhereIn / orWhereNotIn Query Example. The whereIn() method is used to check the value in a given range of the value. So, we will learn laravel 9 whereIn query, laravel 9 whereNotIn query, laravel 9 orWhereIn query, laravel 9 orWhereNotIn query example.

The whereIn method verifies that a given column's value is contained within the given array. The whereNotIn method verifies that the given column's value is not contained in the given array.

Syntax of SQL:

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);

 

Example 1:

In this example, we will retrieve all records of employees with IN conditions.

SELECT * FROM employee WHERE emp_id IN (1,2,3) 

 

Syntax of Laravel:

whereIn(Coulumn Name, Array of Value)

 

 

Example 2:

In this example, we will retrieve data using the whereIn() method.

$employee = DB::table('employee')
                    ->whereIn('id', [1, 2, 3])
                    ->get();

 

Example 3:

In this example, we will retrieve data using the whereNotIn() method.

$employee = DB::table('employee')
                    ->whereNotIn('id', [1, 2, 3])
                    ->get();

 

Example 4:

In this example, we will retrieve data using the orWhereIn() method.

$employee = DB::table('employee')
                    ->where('role','=','software engineer')
                    ->orWhereIn('emp_id', [1, 2, 3])
                    ->get();

 

 

Example 5:

In this example, we will retrieve data using the orWhereNotIn() method.

$employee = DB::table('employee')
                    ->where('role','=','software engineer')
                    ->orWhereNotIn('emp_id', [1, 2, 3])
                    ->get();

 


You might also like:

Recommended Post
Featured Post
How To File Upload Using Node.js
How To File Upload Using Node....

In this example, we will delve into the process of performing file uploads using Node.js. This tutorial will provide you...

Read More

Jul-26-2021

Laravel 10 Send Bulk Mail Using Queue
Laravel 10 Send Bulk Mail Usin...

In this article, we will see laravel 10 send bulk mail using a queue. Here, we will learn about how to send bulk ma...

Read More

Mar-13-2023

How To Get Hourly Data In MySQL
How To Get Hourly Data In MySQ...

In this tutorial, we will see how to get hourly data in mysql. Many times we need to get hourly data or we are required...

Read More

Feb-04-2022

Laravel 9 Firebase Push Notification
Laravel 9 Firebase Push Notifi...

In this article, we will see a laravel 9 firebase push notification, a firebase notification through you can notify...

Read More

Sep-20-2022