Id name order status created 1 john 123 no 2020-07-06 2 deo 788 yes 2020-08-06 3 jane 987 no 2020-09-06 4 deo 234 yes 2020-11-06 #### my $Check_status = $dbh->prepare("SELECT order FROM items ORDER BY created ASC LIMIT 1"); $Check_status->execute(); my $status = $Check_status->fetchrow(); #### if ($status eq 'no') { # skip to next row and check } #### if ($status eq 'yes') { # commit changes # and then continue to check next row }