For example, if one key has two check ins or two check outs in a row, it would be flagged. I'm really not sure how to do this. Any ideas?

It looks likely your table structure is not ideal but if you are stuck with it you can use user defined variables to hold previous record values

SELECT key_number, dateadded, IF (action=@last_action AND key_number=@last_key,"ERROR","OK"), @last_action := action, @last_key := key_number FROM ( SELECT * FROM keysafe ORDER BY key_number, dateadded ) as x

Initialise the variables before use with

$dbh->do('SET @last_action := "UNKNOWN",@last_key="UNKNOWN"');

alternatively use perl variables

my $sql = 'SELECT key_number,action,dateadded FROM keysafe ORDER BY key_number, dateadded'; my $sth = $dbh->prepare($sql); $sth->execute(); my ($last_key,$last_action); while (my ($key,$action,$date) = $sth->fetchrow_array){ my $status = 'OK'; if (($key eq $last_key) && ($action eq $last_action)){ $status = 'ERROR'; }; print "$key,$action,$date,$status\n"; $last_key = $key; $last_action = $action; }
poj

In reply to Re: Searching Database Question by poj
in thread Searching Database Question by htmanning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.