Php 如何使用MySQL确定重复条目

Php 如何使用MySQL确定重复条目,php,mysql,Php,Mysql,我试图确定数据库中最后15个条目是否重复。有没有一种简单的方法可以通过MySQL实现这一点,或者我需要迭代每个结果,并与前一个结果进行比较 我的sql查询如下所示: SELECT content FROM `messages` WHERE sender_id = 12345 order by date desc limit 10 test1 test1 test2 test1 test1 test1 test1 test2 test1 test1 select content, count(

我试图确定数据库中最后15个条目是否重复。有没有一种简单的方法可以通过MySQL实现这一点,或者我需要迭代每个结果,并与前一个结果进行比较

我的sql查询如下所示:

SELECT content FROM `messages` WHERE sender_id = 12345 order by date desc limit 10
test1
test1
test2
test1
test1
test1
test1
test2
test1
test1
select content, count(content) 
from `messages` 
WHERE sender_id = 12345 
group by content
order by count(content) desc
在这种情况下,结果如下所示:

SELECT content FROM `messages` WHERE sender_id = 12345 order by date desc limit 10
test1
test1
test2
test1
test1
test1
test1
test2
test1
test1
select content, count(content) 
from `messages` 
WHERE sender_id = 12345 
group by content
order by count(content) desc
在这种情况下,我希望看到80%的情况是相同的


您对如何使用SQL和PHP轻松完成此任务有何想法或建议?

您可以看到如下重复的数量:

SELECT content FROM `messages` WHERE sender_id = 12345 order by date desc limit 10
test1
test1
test2
test1
test1
test1
test1
test2
test1
test1
select content, count(content) 
from `messages` 
WHERE sender_id = 12345 
group by content
order by count(content) desc

您可以看到重复的数量,如下所示:

SELECT content FROM `messages` WHERE sender_id = 12345 order by date desc limit 10
test1
test1
test2
test1
test1
test1
test1
test2
test1
test1
select content, count(content) 
from `messages` 
WHERE sender_id = 12345 
group by content
order by count(content) desc

如果计数大于1,则为其副本

 SELECT  count(content)  FROM `messages` WHERE sender_id = 12345  group by content order by date desc limit 10

如果计数大于1,则为其副本

 SELECT  count(content)  FROM `messages` WHERE sender_id = 12345  group by content order by date desc limit 10

您可以首先尝试使用
count()
goup by
子句计算每个条目出现的次数:

select content, count(content)
from messages
WHERE sender_id = 12345
    -- maybe add a condition on the date, here
group by content
having count(content) > 1

然后,对于此查询返回的每个内容,您需要做一些事情(如果您尝试删除一些条目,请确保不要删除所有条目,并保留第一个或最后一个条目)

您可以首先尝试使用
count()
goup by
子句来计算每个条目出现的次数:

select content, count(content)
from messages
WHERE sender_id = 12345
    -- maybe add a condition on the date, here
group by content
having count(content) > 1

然后,对于此查询返回的每个内容,您需要做一些事情(如果您尝试删除某些条目,请确保不要删除所有条目,并保留第一个或最后一个条目)

您的总体意图是什么?你想剔除重复,防止重复,计数重复吗?我的目的是标记用户输入90%的重复内容。你的总体意图是什么?你想剔除重复,防止重复,计数重复吗?我的目的是标记用户输入90%的重复内容。很高兴我能提供帮助;玩得高兴很高兴我能帮忙;玩得高兴