building sql query logic
building sql query logic