theinfamousmielie Posted June 23, 2008 Share Posted June 23, 2008 Hey all, Curious question. This is the query i'm running: SELECT Client.Name, Count(Campaign.CampaignID) AS CampaignCount, Count(Content.ContentID) AS ContentCount, Max(Content.UploadDT) AS LastUpload FROM (Client LEFT JOIN Content ON Client.ClientID = Content.ClientID) LEFT JOIN Campaign ON Client.ClientID = Campaign.ClientID GROUP BY Client.Name And this is the result i'm getting: +-----------------------+---------------+--------------+---------------------+ | Name | CampaignCount | ContentCount | LastUpload | +-----------------------+---------------+--------------+---------------------+ | Digiworks | 0 | 0 | NULL | | John Smith Industries | 0 | 0 | NULL | | Pfizer | 6 | 6 | 2008-06-16 17:26:56 | | Playback | 0 | 0 | NULL | +-----------------------+---------------+--------------+---------------------+ ... the problem is: there are only 3 content items, and 2 campaigns 3 * 2 = 6, but why it's returning both 6 for CampaignCount and ClientCount is beyond me. Any ideas? Is it a 'group by' problem? Quote Link to comment Share on other sites More sharing options...
theinfamousmielie Posted June 23, 2008 Author Share Posted June 23, 2008 Nevermind, i couldn't find a way to get it right. The problem was multiple 'counts' of records and a third table involved ... so despite it's inefficiency for now i'm doing SELECT (SELECT COUNT(*) FROM ...) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.