if having statement, use full query