generalize sql_select

I think "sql_select" should be generalized, otherwise I have to build a full sql statement building module.

"sql_select" was called by "build_query", there are a lot of internal functions called by "build_query" and "build_query" hasn't been generalized.