Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top