in reply to Re^3: Detecting 1 day ago
in thread Detecting 1 day ago

Okay, the MySQL way would be something like the following?
SELECT * FROM messages -> WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= message_data;
I generally do this in a three stage format, so if the above is true, I know there's a better way of doing this.
my $data = qq(SELECT * FROM messages..); my $sth = $dbh->prepare($data); $sth->execute();
Instead of caring what results came back, I only need to check to see that at least SOMETHING came back in the last day. How would I do that without having to do an sth->fetch?

Sorry, new to mysql.

Replies are listed 'Best First'.
Re^5: Detecting 1 day ago
by EvanCarroll (Chaplain) on Feb 25, 2006 at 04:43 UTC
    my $sth = $dbh->prepare( q{SELECT 1 FROM messages WHERE DATE_SUB(CURDA +TE(),INTERVAL 1 DAY) <= message_data LIMIT 1; } ); $sth->execute(); print "We got it" if $sth->rows();
    See exists clause if mysql supports it, and if you can make it better fits your needs..


    Evan Carroll
    www.EvanCarroll.com
      Hi.

      Okay, I tried your code and it doesn't error out (which is great!) though I'm not sure what the problem is. It matches something every time. I then changed it down to 1 MINUTE instead of 1 DAY and it still matches every time when the last entry was some hours ago.