Laravel whereIn, whereNotIn With SubQuery Example

In this tutorial you will learn about the Laravel whereIn, whereNotIn With SubQuery Example and its application with practical example.

In this Laravel whereIn and whereNotIn with subquery example article, I’ll show you how to use whereIn and whereNotIn subquery in laravel queries.

Laravel SubQuery

In laravel, sometimes you may want fetch records from multiple database tables having complex and nested relationships. You may also require to exclude some nested data from DB table. So this can be achieved using whereIn and WhereNotIn clause in subquery.

Laravel WhereIn SubQuery

In the given example query we will fetch data from user table, which is available in the user_role table using whereIn subquery.

WhereIn SubQuery Using Query Builder

WhereIn SubQuery Using Model

The above laravel statement given whereIn subQueries represents following SQL query:

Laravel WhereNotIn SubQuery

In the given example query fetch data from user table, which is not available in the user_role table by using whereNotIn subquery.

whereNotIn SubQuery Using Query Builder

WhereNotIn SubQuery Using Model

The above laravel statement given whereNotIn subQueries represents following SQL query:

In this tutorial we have learn about the Laravel whereIn, whereNotIn With SubQuery Example and its application with practical example. I hope you will like this tutorial.