MySQL use GROUP_CONCAT when INSERTing data

yesman

I can't find this on Google. I want to insert into one table the combined information from two columns from a different table. I tried it with the following query, but no luck. What mistake did I make, and is there a better way? How can I make a query like this work?

INSERT INTO newsitem ('id', 'title', 'body') 
VALUES (10, 'Hello world', GROUP_CONCAT(select date, body FROM blog);

Note: Value names have been changed to protect the innocent.

Aziz Shaikh

Try this:

INSERT INTO newsitem ('id', 'title', 'body') 
SELECT 10 AS `id`, 'Hello world' AS title, GROUP_CONCAT(date, body) AS body FROM blog GROUP BY date, body

Your use of GROUP_CONCAT is incorrect, it works inside a SELECT query. You may go through the complete INSERT ... SELECT syntax.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL Use GROUP_CONCAT with Multiple JOINS

From Dev

MySQL - is it possible to use group_concat in an IN() statement?

From Dev

group_concat in mysql with "case when " conditions

From Dev

MySQL GROUP_CONCAT(DISTINCT ...) ignores data

From Dev

PHP group_concat inserting seperator or order by results in no data

From Dev

How to use GROUP_CONCAT in mySQL when one of the fields contain comma seperated numbers?

From Dev

How to COUNT MySQL results when I use “GROUP_CONCAT” and “HAVING” in the query?

From Dev

MySQL - GROUP_CONCAT returns duplicate data, can't use DISTINCT

From Dev

MySQL - GROUP_CONCAT returns duplicate data, can't use DISTINCT

From Dev

MySQL: How to sort when using concat in group_concat?

From Dev

MySQL: How to sort when using concat in group_concat?

From Dev

Invalid use of group function (group_concat and MySQL)

From Dev

how to use select query in a Group_concat sub query in mysql

From Dev

Error when I used GROUP_CONCAT on mysql query

From Dev

MySql group_concat behaviour when used with insert and a limit

From Dev

How to use GROUP_CONCAT with MAX(CASE WHEN...)?

From Dev

Query is not executing properly when I use GROUP_CONCAT with in keyward

From Dev

how to use group_concat for some data like this?

From Dev

MySQL Group_Concat Not In

From Dev

Group_concat use?

From Dev

Group_concat use?

From Dev

GROUP_CONCAT() in MySQL not working while inserting value selecting from an another table

From Dev

MySQL automatically updating field when inserting data

From Dev

PHP MYSQL ERROR when inserting data

From Dev

MySQL automatically updating field when inserting data

From Dev

500 Internal Server when Inserting data to MySQL

From Dev

Inserting Links in GROUP_CONCAT Display

From Dev

Inserting Links in GROUP_CONCAT Display

From Dev

MySQL: update with join using GROUP_CONCAT: ERROR 1111 (HY000): Invalid use of group function

Related Related

  1. 1

    MySQL Use GROUP_CONCAT with Multiple JOINS

  2. 2

    MySQL - is it possible to use group_concat in an IN() statement?

  3. 3

    group_concat in mysql with "case when " conditions

  4. 4

    MySQL GROUP_CONCAT(DISTINCT ...) ignores data

  5. 5

    PHP group_concat inserting seperator or order by results in no data

  6. 6

    How to use GROUP_CONCAT in mySQL when one of the fields contain comma seperated numbers?

  7. 7

    How to COUNT MySQL results when I use “GROUP_CONCAT” and “HAVING” in the query?

  8. 8

    MySQL - GROUP_CONCAT returns duplicate data, can't use DISTINCT

  9. 9

    MySQL - GROUP_CONCAT returns duplicate data, can't use DISTINCT

  10. 10

    MySQL: How to sort when using concat in group_concat?

  11. 11

    MySQL: How to sort when using concat in group_concat?

  12. 12

    Invalid use of group function (group_concat and MySQL)

  13. 13

    how to use select query in a Group_concat sub query in mysql

  14. 14

    Error when I used GROUP_CONCAT on mysql query

  15. 15

    MySql group_concat behaviour when used with insert and a limit

  16. 16

    How to use GROUP_CONCAT with MAX(CASE WHEN...)?

  17. 17

    Query is not executing properly when I use GROUP_CONCAT with in keyward

  18. 18

    how to use group_concat for some data like this?

  19. 19

    MySQL Group_Concat Not In

  20. 20

    Group_concat use?

  21. 21

    Group_concat use?

  22. 22

    GROUP_CONCAT() in MySQL not working while inserting value selecting from an another table

  23. 23

    MySQL automatically updating field when inserting data

  24. 24

    PHP MYSQL ERROR when inserting data

  25. 25

    MySQL automatically updating field when inserting data

  26. 26

    500 Internal Server when Inserting data to MySQL

  27. 27

    Inserting Links in GROUP_CONCAT Display

  28. 28

    Inserting Links in GROUP_CONCAT Display

  29. 29

    MySQL: update with join using GROUP_CONCAT: ERROR 1111 (HY000): Invalid use of group function

HotTag

Archive