fixing sql conditional