11 13 Votes

SQLite: String and Column Concatenation using SQLite

Info by SmartUser | 26/05/2013 at 15:33

Problem: In MySQL, it is possible to join the contents of several columns using CONCAT. It is even possible to include arbitrary strings to the concatenation. When trying CONCAT in SQLite, it only returns an error message: SQLite does not know the CONCAT command. Nevertheless, also with SQLite it is possible to join several strings and columns to display them together as a result.

Solution: The operator for concatenation in SQLite is ||. So, if we want to retrieve the columns "col1" and "col2" from the table "tab" and output their contents in only one column in the result, we can use the following query for this:

SELECT col1 || col2 FROM tab

With this, you can join as many colums as you like. Additionally, you can also add arbitrary other strings and characters:

SELECT 'Column 1: ' || col1 || ', Column 2: ' || col2 FROM tab

This creates an output of the form "Column 1: <contents of col1>, Column 2: <contents of col2>".

ReplyPositiveNegative

About the Author

Avatar AuthorThe author has not added a short description to his profile yet.
Show Profile | Message

 

Related Topics

Quicksort: Sort two Columns
Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.