Question: Hey! i want to know the best solution for my problem.
I have a signature generator <http://www.anitard.org/siggen/siggen_stripes/> where people can upload their own images for the signature. The problem is that my storage will get full pretty fast if i dont somehow have a script that deletes the images when they are done with the signature.

What is the best solution for this?

Answer: 
You have to have something in the lines of:

```
SELECT 
   cmt_id, 
   thread_id, 
   cmt_text 
FROM comments 
WHERE cmt_id IN (
         SELECT 
            MIN(cmt_id) 
         FROM comments 
         GROUP BY thread_id);

```

This is how SQL works, in your query it merges the rows leaving not the row with min cmt\_id but random one (or the last one but I wouldn't count on it). In the above query it would first find all the min ids and then get extended information for each one of them.
```
SELECT *
FROM comments
     INNER JOIN (
       SELECT cmt_id = MIN(cmt_id), thread_id
       FROM comments
       GROUP BY thread_id
     ) cmin ON cmin.cmt_id = comments.cmt_id

```