---
title: "Can I concatenate multiple MySQL rows into one field?"  
description: "Can I concatenate multiple MySQL rows into one field?"  
author: "Revati S Misra"  
published: 2023-07-27  
updated: 2023-07-28  
canonical: https://www.mindstick.com/forum/159336/can-i-concatenate-multiple-mysql-rows-into-one-field  
category: "mysql"  
tags: ["mysql", "database table"]  
reading_time: 2 minutes  

---

# Can I concatenate multiple MySQL rows into one field?

Can I [concatenate](https://www.mindstick.com/interview/1431/how-do-you-concatenate-strings-in-mysql) [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) [MySQL](https://www.mindstick.com/articles/12156/what-is-mysql) rows into one [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing)?

## Replies

### Reply by Aryan Kumar

Yes, you can concatenate multiple MySQL rows into one field using the `GROUP_CONCAT()` function. The syntax is as follows:

SQL

```plaintext
SELECT GROUP_CONCAT(column_name, SEPARATOR) AS column_name
FROM table_name
GROUP BY column_name;
```

For example, if you have a table called `products` with the columns `name` and `price`, you could use the following query to concatenate all product names into a single field:

SQL

```plaintext
SELECT GROUP_CONCAT(name, ',') AS names
FROM products
GROUP BY name;
```

This would return a single field with a comma-separated list of all product names.

Here is an example of how to use the `GROUP_CONCAT()` function in MySQL:

SQL

```plaintext
CREATE TABLE products (
  id INT NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  price INT NOT NULL,
  PRIMARY KEY (id)
);

INSERT INTO products (name, price) VALUES
('Product 1', 100),
('Product 2', 200),
('Product 3', 300);

SELECT GROUP_CONCAT(name, ',') AS names
FROM products
GROUP BY name;
```

This will return the following result:

```plaintext
names
Product 1,Product 2,Product 3
```

As you can see, the `GROUP_CONCAT()` function has concatenated all product names into a single field, separated by commas.

Here are some additional things to keep in mind when using the `GROUP_CONCAT()` function:

- The `GROUP_CONCAT()` function only works with string columns.
- You can use the `SEPARATOR` keyword to specify a different separator character than a comma.
- You can use the `DISTINCT` keyword to remove duplicate values from the results.


---

Original Source: https://www.mindstick.com/forum/159336/can-i-concatenate-multiple-mysql-rows-into-one-field

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
