469,951 Members | 2,717 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

Expired articles appear after expiration date

I have a table, "article" that has a datetime field "article_expires".
In my SQL statement I have this:

Expand|Select|Wrap|Line Numbers
  1. SELECT id, title, body
  2. FROM article
  3. WHERE (article_expires IS NOT NULL OR article_expires = '' OR
  4. article_expires LIKE '0000-00-00%' OR article_expires < now())
  5. ORDER BY ranking DESC, record_entered DESC, upper(title) ASC,
  6. upper(body) ASC
  7.  
Here is info in the table for one row with an expiration date:

----+--------------------------------------------------------------------------+---------------------+
| id | title
| article_expires |
+----+--------------------------------------------------------------------------+---------------------+
| 1 | This article should never appear | 2006-06-12
14:55:36 |
Yet in my resultset this article appears even as of 3:04pm! What am I
possibly doing wrong for this to happen and how can I fix this? The
goal is to only show unexpired articles AND/OR articles that have no
expiration date.

Thanx
Phil

Jun 12 '06 #1
1 1284
>I have a table, "article" that has a datetime field "article_expires".
In my SQL statement I have this:

Expand|Select|Wrap|Line Numbers
  1. SELECT id, title, body
  2. FROM article
  3. WHERE (article_expires IS NOT NULL OR article_expires = '' OR
  4. article_expires LIKE '0000-00-00%' OR article_expires < now())
  •  
  • There's a lot of redundancy here.  if article_expires matches
  • any of the last 3 OR clauses, then it's also not null, so
  • you might as well just say
  •  
  • WHERE article_expires IS NOT NULL
  • ORDER BY ranking DESC, record_entered DESC, upper(title) ASC,
  • upper(body) ASC


  • What is it you're really trying to do?

    Gordon L. Burditt
    Jun 12 '06 #2

    This discussion thread is closed

    Replies have been disabled for this discussion.

    Similar topics

    15 posts views Thread by Oleg Leikin | last post: by
    3 posts views Thread by Green | last post: by
    9 posts views Thread by Mike Reed | last post: by
    3 posts views Thread by Gin | last post: by
    5 posts views Thread by =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post: by
    1 post views Thread by swatiminiyar | last post: by
    By using this site, you agree to our Privacy Policy and Terms of Use.