如何从mysql表中删除具有相同列值的行?
16lz
2021-01-22
I have a problem with my queries in MySQL. My table has 4 columns and it looks something like this:
我的MySQL查询有问题。我的表格有4列,看起来是这样的:
id_users id_product quantity date
1 2 1 2013
1 2 1 2013
2 2 1 2013
1 3 1 2013
id_users
and id_product
are foreign keys from different tables.
id_users和id_product是来自不同表的外键。
What I want is to delete just one row:
我想要的是删除一行:
1 2 1 2013
Which appears twice, so I just want to delete it.
它出现了两次,所以我想删除它。
I've tried this query:
我试着这个查询:
delete from orders where id_users = 1 and id_product = 2
But it will delete both of them (since they are duplicated). Any hints on solving this problem?
但是它会删除它们(因为它们是重复的)。有什么解决这个问题的建议吗?
6 个解决方案
#1
177
Add a limit
to the delete query
向删除查询添加限制
delete from orders
where id_users = 1 and id_product = 2
limit 1
更多相关文章
- win7下Django的MySql安装,问题解决方案
- mysql 事物没提交导致事物一直运行解决方案
- 无法连接远程MySQL数据库的解决方案
- [征集] MySQL交叉表解决方案及散分
- MySQL表格查询基本语句2
- PHP MYSQL 出现中文乱码的解决方案
- Amoeba for MySQL---分布式数据库Proxy解决方案
- MySQL数据库导入或者同步大量数据时数据丢失解决方案
- 关于mysql 和Oracle的一大堆麻烦问题的解决方案