MySQL Select all where DATETIME field is not NULL -


i having trouble selecting proper values query:

select * discounts  disclimit > 0 , disclimit >= discredeemed  or discexp not null , discexp <= now() 

discexp datetime field defaults null.

i trying select current unexpired discounts database:

select * discounts where:

  1. the limit > 0 (a limit exists) , limit >= number redeemed
  2. an expiration exists (not null) , expiration in future

it seems retrieving values datetime field null. appreciated.

you need parentheses! try this:

select * discounts  (disclimit > 0 , disclimit >= discredeemed)  or (discexp not null , discexp <= now()) 

but, question, i'm not sure if or correct. if want meet of following conditions:

  • the limit > 0 (a limit exists)
  • the limit >= number redeemed
  • an expiration exists (not null)
  • the expiration in future

you want, this:

select * discounts  disclimit > 0 , disclimit >= discredeemed , discexp not null , discexp <= now() 

or, if want meet of following conditions:

  • the limit > 0 (a limit exists)
  • the limit >= number redeemed
  • the expiration in future or not exist (is null)

you want this:

select * discounts  disclimit > 0 , disclimit >= discredeemed , (discexp null or discexp <= now()) 

note don't need use discexp not null , discexp <= now(), because null not evaluate being <= anything.

hope helps!


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -