I have a table containing a list of folders, each folder has an ID and Description
SELECT * FROM folders
_id | description
---------------------------
1 | default
2 | test
I have an images table that contains a list of images, each image has a folderid
select folderid, count(*) as imagecount from images GROUP BY folderid;
folderid| imagecount
---------------------------
1 | 4
2 | 5
I want to be able to write a query that returns a list of all folders, with its description, and how many images is inside it
?????
_id | description | imagecount
------------------------------------------------------
1 | default | 4
2 | test | 5
I tried the following query:
SELECT _id, description from folders, (select folderid, count(*) as imagecount from images GROUP BY folder) WHERE _id = folderid;
However it doesn’t work, because it doesn’t return the imagecount column. Any ideas?
This is also a valid SQLite query that will return the answer to your question: how many images in each folder?
or instead of the sum() with a case statement you could just do
count(i.folderid) as imagecount