I am trying to figure out a complex (at least for me!) mysql query and hoped someone here might have some clue's for me..
I have 2 tables "Users" and "files".
Users:
id, name, address, etc..
Files: id, user_id, file_name, etc..
I want to select all rows from Users and in the result create a last column 开发者_如何转开发that has a count of all file with where User.id = Files.user_id.
I tried SELECT * from Users UNION(SELECT COUNT Files.user_id WHERE Users.id = Files.user_id) but doesn't work of course..
select u.*, count(f.id)
from users u
left join files f on u.id = f.user_id
group by u.id
精彩评论