In my MySQL db i have these 3 tables:
ACCOUNT (primary key is name)
name
directory
birthdate
sex
FILES (primary key is id)
id (autoincrement)
name (account foreign key)
filename
uploaded_date
CHECKED (primary key is the couple name - filename)
name (account foreign key)
filename (files foreign key)
I want to make a query that shows a resulting table like this:
RESULT
name - directory - birthdate - sex - filename uploaded_date - checkedCount
Where in checkedCount column i want to have the existing row's count number in CHECKED table for every unique filename.
I tried with this but i had no success:
SELECT * FROM (SELECT * FROM account NATURAL JOIN files) AS table_alias LEFT JOIN (SELECT *, count(*) AS checkedCount FROM checked) AS checked_alias ON table_alias.filename = checked_alias.filename
Currently in ACCOUNT table there are only 2 row, in FILES table 6 rows and in CHECKED tables there are 6 rows with the same name from ACCOUNT and all others 6 unique filenames from FILES.
I can't understand why in my resulting table in checkedCount columns i have all values setted to null, except one that is setted to 6. My goal should be to have all six rows with checkedCount = 1 since every FILE in FILES table is used one times in CHECK table.