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.

4

2 回答 2

0

据我所知,在 MySQL 中最接近 PHP 风格的爆炸是使用 SUBSTRING_INDEX(delim='/',带有负数参数,例如 -1 仅获取文件名): http://dev。 mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index

于 2012-09-02T04:44:18.173 回答
-2

你可以给每个条目一个唯一的 id,mysql 可以自动判断是否有重复的条目,并阻止它被查询到数据库中。在 mysql 手册中查找 UNIQUE INDEX

于 2012-09-02T04:37:57.530 回答