0

I have duplicate images saved in different directories. Because every image location is stored in the database I want to remove duplicate rows of data. I can use this query to look for duplicate image locations in the same directory:

SELECT *
FROM page_additional_images
GROUP BY image_loc
HAVING COUNT(image_loc) > 1

But, it won't work for images in different directories e.g. cars & cars4.

/images/**cars**/hispano-suiza-k6-pictures-and-wallpapers/hispano-suiza-k6.jpg
/images/**cars4**/hispano-suiza-k6-pictures-and-wallpapers/hispano-suiza-k6.jpg

How can I take the query above and look for duplicates ignoring everything before the last "/"?

I want to explode each row by "/" and only query the last element in each array.

1
  • You need to provide schema information. What are your column names and a sample row of data?
    – Kermit
    Sep 2, 2012 at 4:45

2 Answers 2

0

As far as i know, the closest you can get to PHP style explode in MySQL is with SUBSTRING_INDEX (delim='/', with a negative count argument, for example -1 to get only the filename): http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index

-2

You can give each entry a Unique id and mysql can tell automatically if a duplicate entry has been made and will prevent it from being queried into the database. Look up UNIQUE INDEX in the mysql manual

2
  • But, /images/cars4 & /images/cars wouldn't be considered the same. I want to explode each row by "/" and only query the last element in each array.
    – Graham
    Sep 2, 2012 at 4:39
  • This does not address the question.
    – Kermit
    Sep 2, 2012 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.