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

更多相关文章

  1. win7下Django的MySql安装,问题解决方案
  2. mysql 事物没提交导致事物一直运行解决方案
  3. 无法连接远程MySQL数据库的解决方案
  4. [征集] MySQL交叉表解决方案及散分
  5. MySQL表格查询基本语句2
  6. PHP MYSQL 出现中文乱码的解决方案
  7. Amoeba for MySQL---分布式数据库Proxy解决方案
  8. MySQL数据库导入或者同步大量数据时数据丢失解决方案
  9. 关于mysql 和Oracle的一大堆麻烦问题的解决方案

随机推荐

  1. Android 数据存储与读取:SQLite
  2. Android学习——AndroidX
  3. Android:Nothing to show in Android Pro
  4. Edittext android:inputType 输入的限制
  5. Android中Handler引起的内存泄露
  6. android图片压缩质量参数Bitmap.Config R
  7. android sdk 升级出错及解决方案
  8. Android 远程调试 JNI 实现
  9. WebView及js
  10. Java简单模拟Android中Handler-Message机