Here's the main point from the information posted so far - When you JOIN tables, you need to supply a join condition, so that the db server knows what relationship exists between the tables being joined. If you don't supply a join condition, all the rows in the tables being joined will be joined to every row in the query, producing every combination, i.e. a product of all the rows. If you have 4 rows in one table and 5 rows in the other table, you will get 20 rows in the result. If you join with another table that had 2 rows, you would get 40 rows in the result set. When you add the join conditions to your query, you will get only the related rows between the tables joined together.
Next, DISTINCT is not a function. It is a keyword that when present in the sql query removes duplicate rows from the result set. DISTINCT(Filename) is exactly the same as DISTINCT Filename, other columns listed here.... Using DISTINCT to fix the issue at hand isn't working because the other values being selected in the rows are different (they are in fact every possible combination of values), so, nothing is being removed from the result set by having the DISTINCT keyword in the query.
If you post your table definitions and indicate which columns relate the data between the different tables, someone can post a definitive sql statement that will do what you want.