Refactor sqlcompletion to make it work for multiple cols and tables.