-3

table

In these picture you can show one sql table in these table i have a coloum which name is "matrix_unique_id" in thst coloum i have many same id and in each id i store one image the image coloum name is image_path. Now i want to delete all the image in one unique id accept one image.For example: in these 6665682 id i have 25 images now i want to delete all images accept one means when execute the query it delete 24 images and left one.

what i do?

1 Answers1

0

You can use delete join:

delete t1
from yourtable t1
join yourtable t2
on t1.matrix_unique_id = t2.matrix_unique_id
and t1.id < t2.id

this will leave the max(id) of each matrix_unique_id.

Edit: If you want to leave min id, try to change

and t1.id < t2.id

to

and t1.id > t2.id
Blank
  • 12,308
  • 1
  • 14
  • 32