the solution i provided gives you exactly that
perhaps you were confused because i did not post the entire query, so here you go --
WHERE studentid = $input
OR -1 = $input
i don't care whether you use jsp or c-flat or whatever language, but you ~must~ feed the value of the input number (which you said was going to be either a studentid or -1) into the query somehow, and in the solution i gave you, that would be $input, which perhaps confused you because it looks like a php variable
this solution ~is~ in "the DB tier"
this solution ~is~ in the WHERE clause
please, give it a try before you say i didn't understand your requirements