472,139 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

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 1347
>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
    reply views Thread by leo001 | last post: by

    By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

    To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.