Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BETWEEN and OR Select

Tags:

sql

mysql

How I can do to filter in to date range

Select * from  XXX where date between DATE1 AND DATE2 OR Between DATE3 AND DATE4

(Copied from update posted as answer)

Here is my condition

WHERE  ( items_count != '0' )
       AND ( main_table.is_active = '1' )
       AND ( main_table.store_id IN ( '0', '1' ) )
       AND ( main_table.updated_at BETWEEN
             '2011-03-04 16:52:19' AND '2011-03-05 16:52:19'
           )
        OR ( main_table.updated_at BETWEEN
             '2011-03-13 16:52:19' AND '2011-03-14 16:52:19'
           )
LIMIT  0, 30  

The first condition is never used

like image 365
Chaabelasri E. Avatar asked Nov 03 '25 14:11

Chaabelasri E.


1 Answers

Select * from  XXX 
  where (date between DATE1 AND DATE2) 
        OR 
        (date between DATE3 AND DATE4)

EDIT:

Try this:

WHERE items_count != '0' AND 
      main_table.is_active = '1' AND 
      main_table.store_id IN ('0', '1') AND 
      (  main_table.updated_at BETWEEN '2011-03-04 16:52:19' AND '2011-03-05 16:52:19' 
         OR 
         main_table.updated_at BETWEEN '2011-03-13 16:52:19' AND '2011-03-14 16:52:19'
      )
like image 114
codaddict Avatar answered Nov 05 '25 10:11

codaddict



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!