Jump to content

[SOLVED] Not pulling correct number of records from joined tables


Buchead

Recommended Posts

Hello all,

 

Hopefully someone can point out my glaring mistake as I can't see it. I have 2 tables:

 

photofolders:

 

folderID

folderName

folderPosition

 

photos:

 

photoID

photoImage

photoFolder

 

I'm attempting to pull out a list of all the folders, ordered by their folderPosition, and give a count of the number of photos in each of them. I've come up with:

 

SELECT f.*,COUNT(p.photoID) AS ct FROM photofolders AS f LEFT JOIN photos AS p ON f.folderID=p.photoFolder GROUP BY p.photoID ORDER BY f.folderPosition ASC

 

This returns only 3 folders no matter how many are in photofolders. The count is correct for those folders though!  I've tried changing the variable in COUNT to p.photoFolder, and the GROUP BY to match, but it always produces the same count.

 

What have I done wrong?

 

Many thanks,

 

Clive.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.