better sql query for getting last change time in api