Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite selecting two columns (with spaces) as one

This is an extension of this question: SQLite problem selecting two columns as one

How would I combine the two columns if there is a space in the column name?

This works:

SELECT (column1 || " " || column2) AS expr1 FROM your_table;

This does not:

SELECT (column 1 || " " || column 2) AS expr1 FROM your_table;
like image 932
adayzdone Avatar asked Apr 03 '12 03:04

adayzdone


1 Answers

Try this:

 SELECT ("column 1" || ' ' || "column 2") AS expr1 FROM your_table;

OR this

 SELECT ([column 1] || ' ' || [column 2]) AS expr1 FROM your_table;

OR this

 SELECT (`column 1` || ' ' || `column 2`) AS expr1 FROM your_table;

Per the SQLIte documentation, you use single quote for strings, and double for identifiers, but you have the other options for compatibility

  • 'keyword' A keyword in single quotes is a string literal.
  • "keyword" A keyword in double-quotes is an identifier.
  • [keyword] A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility.
  • keyword` A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.
like image 181
Justin Pihony Avatar answered Sep 30 '22 18:09

Justin Pihony