http://www.perlmonks.org?node_id=972404


in reply to Re: database selecting then validating
in thread database selecting then validating

You could simplify that into (assuming a unique constraint on (empid, dept)):

my $sql = 'select 1 from users where empid=? and dept=?'; if ($dbh->selectrow_array($sql, undef, $empid, $dept)) { # valid } else { # not valid }

...I'm always a bit wary of using Count(*) for exists-or-not-exists queries