add a condition to check that first - if function2 returns 0 and apply an AND condition between 2 where clause conditions.. if the first comes out false.. it should probably not check the second condition.. and hence ... see if that works..

what db system are you on? Hope this helps. Regards.