UPDATE with JOIN and GROUP_CONCAT

user2857795

I have 4 tables, one of which I need to update.

  • Table t1 needs to be updated according to the information in table t2 (t1.id = t2.id)

  • Table t2 contains information about websites (e.g.ID, traffic ).

  • Table t3 is a m:n table, that links the IDs in table t2 with the languages in table t4 based on language codes (ISO2) (e.g. XID: 1 | ISO2: EN,DE,FR)

  • Table t4 contains the ISO2-Codes (e.g. EN, DE, FR) and the respective languages (English, German, French)

Now I need to update the languages column in table t1 based on the information in tables t2,t3,t4.

I have written the following query, but it says SQL Error (1111): Invalid use of group function */

UPDATE t1 
LEFT JOIN t2
ON           t1.id = t2.id
LEFT JOIN t3 
ON           t2.id = t3.X_id
LEFT JOIN t4
ON           t3.languages_iso2 = t4.iso2
SET    t1.languages = GROUP_CONCAT(t4.`language` ORDER BY t4.language ASC)

I know that this solution can't be the most elegant one, but my SQL skills are not that good, so I don't know what else I should try. Does anyone have a solution for this problem? Thanks in advance!

Saharsh Shah

Try this:

UPDATE t1 
INNER JOIN (SELECT t2.id, GROUP_CONCAT(t4.language ORDER BY t4.language) languages 
            FROM t2
            INNER JOIN t3 ON t2.id = t3.X_id
            INNER JOIN t4 ON t3.languages_iso2 = t4.iso2
            GROUP BY t2.id
          ) AS t2 ON t1.id = t2.id
SET t1.languages = t2.languages;

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: update with join using GROUP_CONCAT: ERROR 1111 (HY000): Invalid use of group function

From Dev

MySQL group_concat with join

From Dev

select group_concat vs group_concat on left join

From Dev

Mysql with Group by + IF + Left Join + Group_Concat

From Dev

mysql request using join and group_concat

From Dev

Mysql JOIN with GROUP_CONCAT in a complex query

From Dev

GROUP_CONCAT with LEFT JOIN condition?

From Dev

GROUP_CONCAT with join resulting in double records

From Dev

mysql query join group_concat

From Dev

join query with group_concat, duplicate values

From Dev

mysql request using join and group_concat

From Dev

GROUP_CONCAT with join resulting in double records

From Dev

mysql inner join group_concat mysql

From Dev

Using Mysql GROUP_CONCAT in JOIN Query

From Dev

Update mysql table based with group_concat

From Dev

How can I combine GROUP_CONCAT and LEFT JOIN?

From Dev

Codeigniter Multiple Join Not Getting Sub Cat "Name" with Group_Concat

From Dev

Converting MySQL code to Access: GROUP_CONCAT and a triple JOIN

From Dev

Double results in GROUP_CONCAT with double JOIN in MySQL

From Dev

SQL left join and group_concat returns duplicate data

From Dev

MySql duplicated values in a join using GROUP_CONCAT

From Dev

mysql self join with group_concat and without duplicates

From Dev

Search running spatially with PHP, MYSQL, GROUP_CONCAT and JOIN

From Dev

Getting specific in an INNER JOIN mysqli select statement with group_concat

From Dev

Mysql 5.6.12 Group_concat with Inner Join Issue

From Dev

Unexpected result from JOIN and GROUP_CONCAT with three tables

From Dev

MySql duplicated values in a join using GROUP_CONCAT

From Dev

Data.table left join and aggregate/concatenate/group_concat

From Dev

select multiselect values using group_concat and left join

Related Related

  1. 1

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

  2. 2

    MySQL group_concat with join

  3. 3

    select group_concat vs group_concat on left join

  4. 4

    Mysql with Group by + IF + Left Join + Group_Concat

  5. 5

    mysql request using join and group_concat

  6. 6

    Mysql JOIN with GROUP_CONCAT in a complex query

  7. 7

    GROUP_CONCAT with LEFT JOIN condition?

  8. 8

    GROUP_CONCAT with join resulting in double records

  9. 9

    mysql query join group_concat

  10. 10

    join query with group_concat, duplicate values

  11. 11

    mysql request using join and group_concat

  12. 12

    GROUP_CONCAT with join resulting in double records

  13. 13

    mysql inner join group_concat mysql

  14. 14

    Using Mysql GROUP_CONCAT in JOIN Query

  15. 15

    Update mysql table based with group_concat

  16. 16

    How can I combine GROUP_CONCAT and LEFT JOIN?

  17. 17

    Codeigniter Multiple Join Not Getting Sub Cat "Name" with Group_Concat

  18. 18

    Converting MySQL code to Access: GROUP_CONCAT and a triple JOIN

  19. 19

    Double results in GROUP_CONCAT with double JOIN in MySQL

  20. 20

    SQL left join and group_concat returns duplicate data

  21. 21

    MySql duplicated values in a join using GROUP_CONCAT

  22. 22

    mysql self join with group_concat and without duplicates

  23. 23

    Search running spatially with PHP, MYSQL, GROUP_CONCAT and JOIN

  24. 24

    Getting specific in an INNER JOIN mysqli select statement with group_concat

  25. 25

    Mysql 5.6.12 Group_concat with Inner Join Issue

  26. 26

    Unexpected result from JOIN and GROUP_CONCAT with three tables

  27. 27

    MySql duplicated values in a join using GROUP_CONCAT

  28. 28

    Data.table left join and aggregate/concatenate/group_concat

  29. 29

    select multiselect values using group_concat and left join

HotTag

Archive