我正在使用 MySQL 5.7.13
我的数据库中有以下记录,我想根据单列(email_identifier)过滤掉记录。即仅返回单个记录以防特定列具有重复值。
我正在尝试以下查询,但它会引发以下错误
mysql> select * from list_subscriber where list_master_id = 202 group by email_identifier;
错误 1055 (42000):SELECT 列表的表达式 #1 不在 GROUP BY 子句中,并且包含在功能上不依赖于 GROUP BY 子句中的列的非聚合列“db1.list_subscriber.id”;这与 sql_mode=only_full_group_by 不兼容
理想情况下,上述查询应仅返回 1 条记录并包含所有列。
请建议我怎样才能做到这一点?
数据库行示例
mysql> select * from list_subscriber where list_master_id = 202 limit 2\G;
*************************** 1. row ***************************
id: 30518899
list_master_id: 202
unique_identifier: A
email_identifier: xyz@yahoo.co.in
mobile_identifier: 9195423432432
alternate_mobile_identifier:
region_identifier:
city_identifier:
country_identifier:
age_identifier:
gender_identifier:
raw_data: {"user":"A","number":"919542342423","msg":"msg3","emailid":"xyz@vfirst.com"}
created_at: 2016-07-08 15:33:24
updated_at: 2016-08-11 14:55:52
deleted_at: NULL
*************************** 2. row ***************************
id: 30518901
list_master_id: 202
unique_identifier: J
email_identifier: xyz@vfirst.com
mobile_identifier: 919540077166
alternate_mobile_identifier:
region_identifier:
city_identifier:
country_identifier:
age_identifier:
gender_identifier:
raw_data: {"user":"J","number":"919540077166","msg":"msg4","emailid":"xyz@vfirst.com"}
created_at: 2016-07-08 15:34:49
updated_at: 2016-08-11 14:55:52
deleted_at: NULL
更新
CREATE TABLE `list_subscriber` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`list_master_id` int(10) unsigned NOT NULL,
`unique_identifier` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
`email_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`mobile_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`alternate_mobile_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`region_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`city_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`country_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`age_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`gender_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`raw_data` longtext COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `list_subscriber_list_master_id_foreign` (`list_master_id`),
CONSTRAINT `list_subscriber_list_master_id_foreign` FOREIGN KEY (`list_master_id`) REFERENCES `list_master` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=66956432 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci