SQLite Tutorial

  • Home
  • Start Here
  • Views
  • Indexes
  • Triggers
  • Functions
    • Aggregate Functions
    • Date Functions
    • String Functions
    • Window Functions
  • API
    • SQLite Python
    • SQLite Node.js
    • SQLite Java
    • SQLite PHP
  • Try It
Home / SQLite Aggregate Functions / SQLite GROUP_CONCAT

SQLite GROUP_CONCAT

Summary: in this tutorial, you will learn how to use the SQLite GROUP_CONCAT() function to concatenate non-null values in a column.

Introduction to SQLite GROUP_CONCAT() function

The GROUP_CONCAT() function is an aggregate function that concatenates all non-null values in a column.

The following shows the syntax of the GROUP_CONCAT() function:

GROUP_CONCAT(expression [,separator])

In this syntax:

  •  expression is a column or an expression that will be used for concatenation.
  • separator: all values will be separated by the separator. If you skip the separator, the GROUP_CONCAT() function uses a comma (“,”) by default.

SQLite GROUP_CONCAT() function demonstration

First, create a new table named t for the demonstration:

CREATE TABLE t( id INTEGER PRIMARY KEY, val TEXT );

Second, insert three strings into the t table

INSERT INTO t(val) VALUES('A'),('B'),(NULL),('C');

Third, query data from the t table:

SELECT id, val FROM t;

Here is the output:

SQLite GROUP_CONCAT sample table

Fourth, the following statement uses the GROUP_CONCAT() function to concatenate all values in the  val column of the t table:

SELECT GROUP_CONCAT(val) FROM t;

In this example, we did not use the separator, therefore, the GROUP_CONCAT() function uses a comma by default.

The following picture shows the output:

SQLite GROUP_CONCAT example

Fifth, if you don’t want to use a comma as the separator, you can use another string, for example, a semicolon (“;”):

SELECT GROUP_CONCAT(val,';') FROM t;
SQLite GROUP_CONCAT example with separator

SQLite GROUP_CONCAT() function example

The following statement gets the album id and a list of comma-separated track names for each album:

SELECT Title, GROUP_CONCAT(name,';') track_list FROM tracks t INNER JOIN albums a on a.AlbumId = t.AlbumId GROUP BY Title ORDER BY Title;

The output is shown as follows:

SQLite GROUP_CONCAT practical example

In this example:

  • First, the GROUP BY clause divides the tracks by album into groups.
  • Then, the GROUP_CONCAT() function applies to each group to concatenate track names.

In this tutorial, you have learned how to use the SQLite GROUP_CONCAT() function to concatenates all non-null values in a column.

  • Was this tutorial helpful ?
  • YesNo
Previous SQLite SUM

Getting Started

  • What Is SQLite
  • Download & Install SQLite
  • SQLite Sample Database
  • SQLite Commands

SQLite Tutorial

  • SQLite Select
  • SQLite Order By
  • SQLite Select Distinct
  • SQLite Where
  • SQLite Limit
  • SQLite BETWEEN
  • SQLite IN
  • SQLite Like
  • SQLite IS NULL
  • SQLite GLOB
  • SQLite Join
  • SQLite Inner Join
  • SQLite Left Join
  • SQLite Cross Join
  • SQLite Self-Join
  • SQLite Full Outer Join
  • SQLite Group By
  • SQLite Having
  • SQLite Union
  • SQLite Except
  • SQLite Intersect
  • SQLite Subquery
  • SQLite EXISTS
  • SQLite Case
  • SQLite Insert
  • SQLite Update
  • SQLite Delete
  • SQLite Replace
  • SQLite Transaction

SQLite Data Definition

  • SQLite Data Types
  • SQLite Date & Time
  • SQLite Create Table
  • SQLite Primary Key
  • SQLite Foreign Key
  • SQLite NOT NULL Constraint
  • SQLite UNIQUE Constraint
  • SQLite CHECK Constraint
  • SQLite AUTOINCREMENT
  • SQLite Alter Table
  • SQLite Rename Column
  • SQLite Drop Table
  • SQLite Create View
  • SQLite Drop View
  • SQLite Index
  • SQLite Expression-based Index
  • SQLite Trigger
  • SQLite VACUUM
  • SQLite Transaction
  • SQLite Full-text Search

SQLite Tools

  • SQLite Commands
  • SQLite Show Tables
  • SQLite Describe Table
  • SQLite Dump
  • SQLite Import CSV
  • SQLite Export CSV

SQLite Functions

  • SQLite AVG
  • SQLite COUNT
  • SQLite MAX
  • SQLite MIN
  • SQLite SUM

SQLite Interfaces

  • SQLite PHP
  • SQLite Node.js
  • SQLite Java
  • SQLite Python

About SQLite Tutorial

SQLite Tutorial website helps you master SQLite quickly and easily. It explains the complex concepts in simple and easy-to-understand ways so that you can both understand SQLite fast and know how to apply it in your software development work more effectively.

Looking for a tutorial…

If you did not find the tutorial that you are looking for, you can use the following search box. In case the tutorial is not available, you can request for it using the request for a SQLite tutorial form.

Recent Tutorials

  • SQLite IIF
  • SQLite Generated Columns
  • SQLite Getting Started
  • SQLite Programming Interfaces
  • SQLite Concat
  • SQLite INSTEAD OF Triggers
  • SQLite Join
  • SQLite IS NULL

Site Links

  • Home
  • About
  • Contact
  • Resources
  • Privacy Policy

Copyright © 2020 SQLite Tutorial. All Rights Reserved.