MySQL 获得相同的差异 table

MySQL Get difference within same table

我有这个tablefiddle

如您所见,我得到了 6 行,现在我的问题是我只想要唯一的 4 条记录,并将事件作为分组依据,而不是得到 1、2、3、4,我想要 5、6、3, 4 (id)

我的意思是"give me all those unique records where organization id = 0 or 5 but reject organization id 0 records only if it exists in organization id 5"

select max('id'),max(`organization_id`),`title`,`event`,`html_template`,`is_default` 
from templates 
group by `title`,`event`,`html_template`,`is_default`;

试试这个:-

SELECT MAX(`id`), MAX(`organization_id`), `title`, `event`, `html_template`, `is_default`
FROM `templates`
GROUP BY `title`, `event`, `html_template`, `is_default`

这里是 fiddle:-

http://sqlfiddle.com/#!2/ea9211/31