Selecting columns from an SQLite table and formatting the output