Mysql数据库中多条重复数据,如何只删除一条?
3个回答
展开全部
这条语句写的太乱了吧.....
delete
from
customers_basket
where
id=(select
cb.id
from
orders
o,orders_products
op,customers_basket
cb
where
o.orders_status=4
and
op.orders_id
=
o.orders_id
and
op.products_id
=
cb.products_id
and
cb.customers_id
=
o.customers_id);
试一下
delete
from
customers_basket
where
id=(select
cb.id
from
orders
o,orders_products
op,customers_basket
cb
where
o.orders_status=4
and
op.orders_id
=
o.orders_id
and
op.products_id
=
cb.products_id
and
cb.customers_id
=
o.customers_id);
试一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
列出要保留的记录ID,可以把这个结果写到一个临时表t1中:
SELECT
MAX(id)
AS
max_id
FROM
pedigree
GROUP
BY
number
然后:DELETE
FROM
pedigree
WHERE
id
NOT
IN
(SELECT
id
FROM
t1)
也就是:delete
from
pedigree
where
id
not
in(select
*
from
pedigree
where
group
by
number)。
pedigree
where
id
not
in(select
max(id)
from
pedigree
where
group
by
number
having
count(id)
>
0)
查询结果是否符合删除要求!
SELECT
MAX(id)
AS
max_id
FROM
pedigree
GROUP
BY
number
然后:DELETE
FROM
pedigree
WHERE
id
NOT
IN
(SELECT
id
FROM
t1)
也就是:delete
from
pedigree
where
id
not
in(select
*
from
pedigree
where
group
by
number)。
pedigree
where
id
not
in(select
max(id)
from
pedigree
where
group
by
number
having
count(id)
>
0)
查询结果是否符合删除要求!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询