mysql remove row_Find and remove MySQL row duplicates that are right after each other

I'm trying to find and remove MySQL row duplicates that are right after each other, instead of finding all, even if they're not straight after each other.

SELECT DISTINCT(content) AS contentMsg, COUNT(*) AS cnt, `ticketId`,`date`

FROM ticketsReplies

WHERE username = 'X'

GROUP BY contentMsg, ticketId

HAVING cnt > 1

ORDER BY cnt DESC

This is my current code. However, this finds duplicates if there's just two of the same answers in one ticket instead of them having to be IDs right after each other (which can happen if you send a POST request, and it fails, and you refresh etc).

How would I go about finding ones that are only 1 ID from each other.

So finding e.g. 1,2,3,4,5,6,7 instead of 1,3,9,11

E.g. if you have

ID EMAIL

---------------------- --------------------

1 aaa

2 bbb

3 bbb

4 bbb

5 ddd

6 eee

7 aaa

8 aaa

9 bbb

If you have this, it should find the following IDs: 2,3,4 but not 9 as it's not directly after 4 even though its a duplicate.

It should also find 7,8 but not 1 as they are not right after each other.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值