帮助删除行mysql

时间:2010-11-04 14:01:07

标签: mysql

我真的很感谢删除此查询返回的行的一些帮助:

select count(av.sesskey) as total from also_viewed av where av.sesskey not in(select op.sesskey from orders_products op) group by av.sesskey having total = 1

非常感谢所有人

4 个答案:

答案 0 :(得分:0)

试试这个:

DELETE FROM also_viewed
WHERE   sesskey IN (
            SELECT  Distinct sesskey
            FROM    also_viewed
            WHERE   sesskey NOT IN (SELECT sesskey FROM order_products)
            GROUP BY sesskey
            HAVING  COUNT(1) = 1
        )

答案 1 :(得分:0)


DELETE 
av1
FROM also_viewed av1,
     (SELECT count(av.sesskey) as total, av.sesskey as key 
      FROM also_viewed av 
      WHERE av.sesskey NOT IN (SELECT op.sesskey FROM orders_products op) GROUP BY av.sesskey HAVING total = 1) AS innerQuery
WHERE av1.sesskey = innerQuery.key

在DELETE关键字和FROM关键字之后,您可以指定要消除匹配行的表。

答案 2 :(得分:0)

未经测试

DELETE FROM also_viewed av 
WHERE av.sesskey NOT IN
    (SELECT op.sesskey FROM ORDERS_PRODUCTS op)
GROUP BY av.sesskey HAVING COUNT(av.sesskey) = 1;

答案 3 :(得分:0)

你的sql返回匹配的行数而不是行本身
使用delte syntax删除行

delete from
  also_viewed
where
  sesskey not in(select op.sesskey from orders_products op) 

PS:先备份;我不完全确定我是否理解你的查询