如何在mysql中使用join删除表中的重复项

gorkyyrv  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(407)
select * 
from
(
  SELECT  id, imei1, status
  FROM `owarranty_imei` mto 
  WHERE EXISTS
  (
    SELECT 1 
    FROM `owarranty_imei` mti 
    WHERE mto.imei1=mti.imei1 
    LIMIT 1, 1
  )
) t1 
left join `owarranty_warranty_activations` as t2 on t1.id=t2.imei_id
where t2.id is null 
limit 100

这是我的问题。在奥瓦兰蒂,伊梅有超过10万张唱片。我想从imei表中获取owarranty\U imei不在owarranty\U激活表中的副本。这个查询只对少数记录起作用,但当我对超过1000000条记录运行它时,它就不起作用了

ngynwnxp

ngynwnxp1#

SELECT  
       mto.id, 
       mto.imei1, 
       mto.status
  FROM 
      `owarranty_imei` mto 
          INNER JOIN 
      `owarranty_imei` mti ON mto.imei1=mti.imei1 
          LEFT JOIN 
      `owarranty_warranty_activations` as t2 ON mto.id=t2.imei_id
  GROUP BY mto.id
  HAVING COUNT(t2.id)=0

相关问题