Okay, two admissions here, one is I’m sure this question has been answered and it has something to do with a join and the second is I’m not sure why I’m writing an application which requires complex SQL when I don’t really know SQL.
Here’s the problem, most likely it’s cake walk, but I can’t seem to find the answer on here;
I have a select which returns an ID and a sum of items from a table. I want to take the ID and resolve this as the actual name.
Here’s the query;
select top 10
sum(elapsedTimeSeconds) as et, AppID
from UsersAppLog
where userid = 1
and appid <> 7
and CreatedOn > '01 Sep 2011'
group by
AppID
order by
et desc
so I get;
et, appid
and I want to lookup “description” from the windowsapps table based on the returned appid.
Any help would be appreciated.
Phil.
Just add the column you need to the query and the GROUP BY clause:
Not knowing your exact schema (it would help for the future to post those things!), I’ve guessed that you have an
AppIDin theWindowsApplicationstable, too – and I’ve assumed all youru.AppIDwill have a proper match – therefore theINNER JOINI would also recommend to always use the ISO-8601 date format (
YYYYMMDD) – it’s the only way to make sure your code will work regardless of the locale/regional/language setting on the SQL Server machine in question.