Mysql
 sql >> Base de données >  >> RDS >> Mysql

Requête donnant un résultat en double ?

Trois façons de résoudre ce problème (en gros, vous avez plus d'une ligne dans 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