2016-05-06 19 views
1

グループconcatで3つのテーブルを結合しようとしています。メインテーブルがjsonフォーマットのカラムを結合しています。3つのテーブルをSQLのグループ連結と結合する方法

クエリが動作しますが、何度も何度も クエリを結合列のデータを繰り返している - >

[SELECT tour_package.description AS description, 
     tour_package.NAME AS NAME, 
     GROUP_CONCAT(destination_continent.NAME) AS continent_name, 
     GROUP_CONCAT(travel_style.NAME) AS travel_style_name, 
     tour_package.id AS id, 
     tour_package.img_path_thumb AS img_path_thumb, 
     tour_package.continent_id, 
     tour_package.travel_style_id 
FROM tour_package 
LEFT JOIN destination_continent ON 
     FIND_IN_SET(destination_continent.id, 
      REPLACE(REPLACE(REPLACE(tour_package.continent_id, '\[', '') , '\]', '') , '\"', '')) 
LEFT JOIN travel_style ON 
     FIND_IN_SET(travel_style.id, 
      REPLACE(REPLACE(REPLACE(tour_package.travel_style_id, '\[', '') , '\]', '') , '\"', '')) 
WHERE `tour_package`.`DELETE` = 0 && `destination_continent`.`DELETE` = 0 
LIMIT 0 , 30][1] 

テーブル - GROUP_CONCAT中>image1

image2

image3

答えて

0

使用DISTINCTキーワード関数

すなわち:

SELECT tour_package.description AS description, 
     tour_package.NAME AS NAME, 
     GROUP_CONCAT(DISTINCT destination_continent.NAME) AS continent_name, 
     GROUP_CONCAT(DISTINCT travel_style.NAME) AS travel_style_name, 
     tour_package.id AS id, 
     tour_package.img_path_thumb AS img_path_thumb, 
     tour_package.continent_id, 
     tour_package.travel_style_id 
.... 
+0

のthnxを行う一方で、私はメモリのためのトニックを取らなければなりません –

0

グループ連結は、今私は私の自己に笑っています、Distinctチェック

[SELECT tour_package.description AS description, tour_package.NAME AS NAME, GROUP_CONCAT(DISTINCT(destination_continent.NAME)) AS continent_name, GROUP_CONCAT(DISTINCT(travel_style.NAME)) AS travel_style_name, tour_package.id AS id, tour_package.img_path_thumb AS img_path_thumb, tour_package.continent_id, tour_package.travel_style_id FROM tour_package LEFT JOIN destination_continent ON FIND_IN_SET(destination_continent.id, REPLACE(REPLACE(REPLACE(tour_package.continent_id, '\[', '') , '\]', '') , '\"', '')) LEFT JOIN travel_style ON FIND_IN_SET(travel_style.id, REPLACE(REPLACE(REPLACE(tour_package.travel_style_id, '\[', '') , '\]', '') , '\"', '')) WHERE `tour_package`.`DELETE` =0 && `destination_continent`.`DELETE` =0 LIMIT 0 , 30][1] 
関連する問題