I\'ve got a table of \'folders\'. I want to return all the records with the userId of 16.
SELECT * FROM `folders` WHERE userId = 16;
I\'ve
Do a sub query that groups by the Folders to get the count per folder, then join it to the first query like this:
select
f.*
fc.Files
from
Folders f
--
-- Join the sub query with the counts by folder
JOIN (select
Folder,
count(*) Files
from
files
group by
Folder ) as fc
on ( fc.Folder = f.Folder )
where
f.userid = 16