Your Guide to Laravel Excellence

Faster Query with `whereIntegerInRaw` Method

Faster Query with `whereIntegerInRaw` Method

In this article we will learn about whereIn and whereIntegerInRaw, both these methods are used to add a "where in" clause to your database queries.

whereIn Method

The whereIn method is typically used for standard queries where the column can be any data type (string, integer, etc.).

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

The whereIntegerInRaw method is very useful where the column is an integer and you need a more efficient query.This method can be useful when you are working with a large set of integers.

DB::table('users')->whereIntegerInRaw('id', [1, 2, 3])->get();

Summary

  • whereIn can handle various data types.

  • whereIntegerInRaw is optimized for integer columns

  • Use whereIn when you are dealing with columns that might not strictly be integers or when the set of values includes different data types.

  • Use whereIntegerInRaw when you are sure that the column and the values are integers.

Recommeded Posts

New in Laravel 12: Eager Loading, Attribute Scopes, and fromJson

New in Laravel 12: Eager Loading, Attribute Scopes, and fromJson

Discover the new features in Laravel 12! Learn about automatic eager loading, easier query scopes with PHP attributes, and the new Collection::fromJson() method

2 months ago Read article →
Multi language in laravel 11

Multi language in laravel 11

Multi language in laravel 11

2 months ago Read article →
Resize Images using intervention-image

Resize Images using intervention-image

Resize Images using intervention-image

2 months ago Read article →
How to Use Lateral Joins in Laravel for Fetching Limited Records

How to Use Lateral Joins in Laravel for Fetching Limited Records

How to Use Lateral Joins in Laravel for Fetching Limited Records

2 months ago Read article →