Extracted base sql to private method.