本文介绍了查询给出重复的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的查询:

SELECT b.id,b.body FROM btin b
INNER JOIN nwork n ON (n.mem_id = b.mem_id)
WHERE b.parentid = '0'
AND ('401' IN (n.frd_id, b.mem_id))
ORDER BY b.date DESC
LIMIT 20 OFFSET 0

问题在于它的打印重复结果.我该如何优化这个

the problem is its printing duplicate result.How can I optimize this one

请帮忙谢谢

推荐答案

解决这个问题的三种方法(基本上你在 nwork 中有超过 1 行):

Three ways to solve this (basically you have more than 1 row in nwork):

SELECT distinct b.id,b.body FROM btin b
INNER JOIN nwork n ON (n.mem_id = b.mem_id)
WHERE b.parentid = '0'
AND ('401' IN (n.frd_id, b.mem_id))
ORDER BY b.date DESC
LIMIT 20 OFFSET 0


SELECT  b.id,b.body
FROM btin b
Where b.id in (SELECT  b.id FROM btin b  INNER JOIN nwork n ON (n.mem_id = b.mem_id)
                WHERE b.parentid = '0' AND ('401' IN (n.frd_id, b.mem_id)))
ORDER BY b.date DESC
LIMIT 20 OFFSET 0

SELECT  b.id,b.body FROM btin b
INNER JOIN nwork n ON (n.mem_id = b.mem_id)
WHERE b.parentid = '0'
AND ('401' IN (n.frd_id, b.mem_id))
Group by b.id, b.body, b.date
ORDER BY b.date DESC
LIMIT 20 OFFSET 0

这篇关于查询给出重复的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 23:48