Here is my scenario as beginner in mysql.
There are 2 tables.
I need to insert rows in wp_usermeta based on users_roles.rid value.
textA + meta_value from rows with meta_key dokan_site_name already existing in wp_usermeta + textB.
There is my problem. I can't figure out the right way to achieve the CONCAT properly.
When i run this i get : #1242 - Subquery returns more than 1 row
INSERT INTO usermeta (
user_id,
meta_key,
meta_value
)
SELECT
uid,
'dokan_profile_settings',
CONCAT('textA', (SELECT usermeta.meta_value FROM usermeta WHERE usermeta.meta_key LIKE 'dokan_store_name'), 'textB')
AS meta_value
FROM users_roles WHERE rid LIKE '4';
If i just run the SELECT part of the CONCAT, as pointed out in Paul's comment :
SELECT usermeta.meta_value FROM usermeta
WHERE usermeta.meta_key LIKE 'dokan_store_name'
I get the intended result, but i can't figure out why the whole query fails.
As the error message states, you can't use a subquery that returns more than one string value in a CONCAT() function.
An easy way to solve this would be to GROUP_CONCAT() the results of your subquery: CONCAT('textA', (SELECT GROUP_CONCAT(usermeta.meta_value) FROM usermeta WHERE usermeta.meta_key LIKE 'dokan_store_name'), 'textB')