Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can this be done? (n00b question)

Author  Topic 

joblenis
Starting Member

29 Posts

Posted - 2007-04-10 : 11:38:13
I am trying to do a group by and left join together but it does not seem to be working.

SELECT sb.[BrowserID]
,sum([BrowserTotal])
,[BrowserName]
FROM [IISLOG_REPORTS].[statistics].[browser] sb
left join [IISLOG_REPORTS].[lookups].[browser] lb on sb.browserid=lb.browserid
GROUP BY sb.[BrowserID]
ORDER BY sb.[BrowserID]

The above code works without the blue line there (which is being fetched from the lb table). Any suggestions for this? I would need all 3, including the BrowserName. Thanks

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2007-04-10 : 11:43:59
Try

SELECT sb.[BrowserID]
,[BrowserName]
,sum([BrowserTotal])

FROM [IISLOG_REPORTS].[statistics].[browser] sb
left join [IISLOG_REPORTS].[lookups].[browser] lb on sb.browserid=lb.browserid
GROUP BY sb.[BrowserID],[BrowserName]
ORDER BY sb.[BrowserID]

Every field that isn't an aggregate needs to be in the group by clause.

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

joblenis
Starting Member

29 Posts

Posted - 2007-04-10 : 11:51:02
Thanks that works great. I'll keep that in mind next time.
Go to Top of Page
   

- Advertisement -