MySQL value BETWEEN Two Columns in Laravel

MySQL value BETWEEN Two Columns in Laravel

Today, We are going to learn how to fine MySQL value BETWEEN Two Columns in Laravel. In one of my project, I need to find the value BETWEEN two columns and fetch the records. Laravel allows us to write raw query using DB::raw method.

MySQL BETWEEN Two Columns in Laravel

First of all, We are going to write the Laravel raw query for finding the MySQL value BETWEEN Two Columns.

Just follow the query for finding the number between two columns.

    $items = Availability::whereRaw(
        \DB::raw(' 25 BETWEEN `from_no` AND `to_no` ')
    )->get();

Also, We can achieve the same result using less than or greater than like below.

$itemExits = Availability::where('from_no','<=',25)
        ->where('to_no','>=',25)
        ->get();

Both queries are working fine with Laravel for finding the MySQL value BETWEEN Two Columns in Laravel. Even you can use this query in core PHP. I hope the article is helpful to you.

If you face any issue after following the query please write the comment.

Related Posts

  1. PHP tree structure for categories and sub categories without looping a MySQL query
  2. Email unique validation in Laravel ignore id on update
  3. WordPress Button Shortcode – Add button to WordPress editor
  4. WordPress shortcode – How to create shortcode in WordPress
  5. WordPress change URL in database using MySQL Query
  6. PHP remove HTML tags from string using strip_tags
  7. Enable shortcodes in widget WordPress
  8. PHP remove non-empty directory programmatically
  9. PHP File upload step by step with example
  10. Laravel 6 integrate AdminLte admin theme jeroennoten

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search Posts

Subscribe To Newsletter

Get Early Access To New Articles, Plugins, Discount Codes And Quickly Brief Updates about tips and tricks

Join 358 other subscribers