0

I have this MySQL table:

+------+------+
| id   | name |                                                                                                                                               
+------+------+                                                                                                                                               
|    1 | John |                                                                                                                                               
|    1 | John |                                                                                                                                               
|    2 | Jill |                                                                                                                                               
|    2 | Jill |                                                                                                                                               
|    3 | Jack |                                                                                                                                               
|    3 | Jack |                                                                                                                                               
+------+------+

Can anyone please tell me how to delete the duplicate records and keep one record from this table in MySQL in one single query (i.e without creating another table)?

Aaron Christiansen
  • 11,584
  • 5
  • 52
  • 78
hjunaid
  • 11
  • 6
  • 1
    Possible duplicate : http://stackoverflow.com/questions/4685173/delete-all-duplicate-rows-except-for-one-in-mysql – Isky Mar 23 '16 at 16:58
  • Hi Mattia,The id in my table is not unique. So I cannot use that query – hjunaid Mar 23 '16 at 17:10
  • If you don't have an uniq identifier how I think you can't only one row. – Isky Mar 23 '16 at 19:14
  • Welcome to SO. We'd like to see your attempt at solving this. Please supply your query and what it's result is. Or, show us where you searched toward solving this and why it didn't help you. "[ask]" and "[mcve]" will help. – the Tin Man Mar 25 '16 at 17:41

1 Answers1

-1

You have basically two options unless you want to do something more precise:

select * from table group by ID

or, alternatively:

select distinct(ID), name from table

Giovanni
  • 32
  • 1