How to delete a certain row from mysql table with same column values

0 votes

I have a problem with my queries in MySQL. My table has 4 columns and it looks something like this:

id_users    id_product    quantity    date
 1              2              1       2020
 1              2              1       2020
 2              2              1       2020
 1              3              1       2020

id_users and id_product are foreign keys from different tables.

What I want is to delete just one row:

1     2     1    2020

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?

Aug 26, 2020 in PHP by kartik
• 37,490 points
108 views

1 answer to this question.

0 votes

Hello @kartik,

Add a limit to the delete query

delete from orders 
where id_users = 1 and id_product = 2
limit 1

Hope it helps!!
Thank you!!

answered Aug 26, 2020 by Niroj
• 82,680 points

Related Questions In PHP

0 votes
1 answer

How to convert from MySQL datetime to another format with PHP?

Hello, To convert a date retrieved from MySQL ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,680 points
189 views
0 votes
1 answer

How to see indexes for a database or table in MySQL?

Hello @kartik, To see the index for a ...READ MORE

answered Aug 18, 2020 in PHP by Niroj
• 82,680 points
193 views
0 votes
1 answer

How to move columns in a MySQL table?

Hello @kartik, If empName is a VARCHAR(50) column: ALTER ...READ MORE

answered Aug 19, 2020 in PHP by Niroj
• 82,680 points
146 views
0 votes
1 answer

How to alter a MySQL column to be AUTO_INCREMENT?

Hello @kartik, Try this: ALTER TABLE document MODIFY COLUMN ...READ MORE

answered Aug 19, 2020 in PHP by Niroj
• 82,680 points
90 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,680 points
6,715 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,680 points
781 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
584 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
7,133 views
0 votes
1 answer

How to delete duplicates on a MySQL table?

Hello @kartik, This removes duplicates in place, without ...READ MORE

answered Aug 26, 2020 in PHP by Niroj
• 82,680 points
235 views
0 votes
1 answer

How I can make a query with MySQL that checks if the valuein a certain column contains certain data?

Hello @kartik, Try this query: mysql_query(" SELECT * FROM `table` WHERE `column` ...READ MORE

answered Sep 13, 2020 in PHP by Niroj
• 82,680 points
124 views