Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,


mysql delete command in single table no primary key for the table. i have inserted records for same id, same name for two records. i need to delete 1 record from the single table

id name
1 test
1 test


i need to delete one record
Posted
Comments
Mohibur Rashid 2-Jul-12 2:22am    
You better write an application from where you can identify the duplicate id and can delete except one

try like this

SQL
DELETE FROM Sample WHERE id=1 LIMIT 1;

or
SQL
DELETE FROM Sample WHERE id IN (SELECT id FROM Sample GROUP BY id HAVING COUNT(*) > 1) LIMIT 1
 
Share this answer
 
v2
Comments
Mohibur Rashid 2-Jul-12 2:20am    
Yup it is how to do it, but the second query wont work
Hi,
delete any one value in identical rows by using rownum.

Regards
 
Share this answer
 
SQL
delete from <table name=""> where <primarykey> = <string></string></primarykey></table>
 
Share this answer
 
hi,

i have already tried for these type of queries

I t show the error message like this while using



DELETE FROM Sample WHERE id IN (SELECT id FROM Sample GROUP BY id HAVING COUNT(*) > 1) LIMIT 1

You can't specify target table 'i_t' for update in FROM clause

The inner query which shows the record 1 but we cannot use same table in inner and outer query

have u tried the query what u have send
 
Share this answer
 
Please follow the steps:

1. select distinct rows from your table and
2. insert into a new temporary table.
3. Delete all the rows from your original table.
4. insert all the rows from temporary table to your original table.


Hope it work
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900