Mariadb
可能包括重複的行?
我有 MariaDB 版本 10.2.14-MariaDB。我有一個看起來像這樣的表:
CREATE TABLE `card_data_link` ( `card_id` INT(11) NULL DEFAULT NULL, `data_id` INT(11) NULL DEFAULT NULL, INDEX `card_id` (`card_id`) USING BTREE, INDEX `data_id` (`data_id`) USING BTREE ) COLLATE='utf8_general_ci' ENGINE=InnoDB ;
它有這些數據:
card_id data_id "63" "21" "34" "3" "34" "21" "34" "21"
它加入了這個:
CREATE TABLE `card_data` ( `data_id` INT(11) NOT NULL AUTO_INCREMENT, `data` TEXT NULL DEFAULT NULL COLLATE 'utf8_general_ci', PRIMARY KEY (`data_id`) USING BTREE ) COLLATE='utf8_general_ci' ENGINE=InnoDB AUTO_INCREMENT=51 ;
它的數據如下所示:
data_id data "21" "{R}" "3" "{3}"
如果我執行此查詢:
select cdl.card_id, cdl.data_id, cd.data from card_data_link cdl left join card_data cd on cd.data_id = cdl.data_id group by cdl.card_id ,cd.data_id
結果:
card_id data_id data "34" "3" "{3}" "34" "21" "{R}" "63" "21" "{R}"
有沒有辦法讓我獲得第二個
"34" "21" "{R}"
行顯示,因此它返回:
card_id data_id data "34" "3" "{3}" "34" "21" "{R}" "34" "21" "{R}" "63" "21" "{R}"
就像它在做一個選擇不同的,即使我沒有把不同的。我沒有正確分組嗎?謝謝!
GROUP BY``SELECT
根據其參數聚合語句的結果值。從 SQL 中刪除
GROUP BY
子句和參數將允許出現重複項。對於 MariaDB 推薦
sql_mode=ONLY_FULL_GROUP_BY
(非預設,參考:手冊),以確保 SQL 語句相對於GROUP BY
.