Concatenates string values from multiple rows into a single string with a specified delimiter. Very useful for creating lists or comma-separated values in BigQuery.
STRINGDiperbarui: 13 Jun 2026STRING_AGG([DISTINCT] expression [, delimiter] [ORDER BY key])A string column or expression to concatenate
Separator between values (default: comma ',')
Default: ','
Concatenate only unique values
Sort values before concatenating
1 SELECT 2 customer_id, 3 STRING_AGG(product_name, ', ') as purchased_products 4 FROM `project.dataset.orders` 5 GROUP BY customer_id 6 LIMIT 3;
Creates a list of products purchased per customer.
| customer_id | purchased_products |
|---|---|
| C001 | Laptop, Mouse, Keyboard |
| C002 | Monitor, USB Hub |
| C003 | Headphone, Webcam, Microphone |
1 SELECT 2 department, 3 STRING_AGG(employee_name, '; ' ORDER BY hire_date) as employees_by_seniority 4 FROM `project.dataset.employees` 5 GROUP BY department;
Concatenates employee names sorted by their hire date.
| department | employees_by_seniority |
|---|---|
| Engineering | Alice; Bob; Charlie; Diana |
| Marketing | Eve; Frank; Grace |
1 SELECT 2 order_date, 3 STRING_AGG(DISTINCT category, ', ' ORDER BY category) as categories_sold 4 FROM `project.dataset.sales` 5 GROUP BY order_date 6 ORDER BY order_date DESC 7 LIMIT 3;
Displays unique categories sold per day.
| order_date | categories_sold |
|---|---|
| 2024-06-25 | Books, Electronics, Fashion |
| 2024-06-24 | Electronics, Food, Home |
| 2024-06-23 | Books, Fashion, Sports |
1 SELECT 2 user_id, 3 '[' || STRING_AGG('"' || tag || '"', ', ') || ']' as tags_json 4 FROM `project.dataset.user_tags` 5 GROUP BY user_id;
Sudah paham STRING_AGG? Latih langsung di browser
Latihan interaktif, langsung di browser.
Builds a JSON array format from tags.
| user_id | tags_json |
|---|---|
| U001 | ["python", "sql", "data"] |
| U002 | ["javascript", "react"] |