If statement for two different sql queries