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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-06-24 : 07:25:54
|
| Chris writes "I use SQL Server 2000 on Windows 2000. I use 2 tables for operating a mail list. I need a solution to get the number of times that a entry re-appears in a given select statement. I have the following tables:1) ArticleID, Title, Article2) SentID, DateSent, ArticleIDI have joined these 2 tables so that I can have an easy output of what articles have been sent.SELECT tblArticle.*, tblSentArticles.*FROM tblArticle LEFT JOIN tblSentArticles ON tblArticle.ArticleID = tblSentArticles.ArticleID;I need some kind of output that can show me how many times an article have been sent. Would it be possible to have some kind of function to do something like the example belowArticleID, Title, Article, TotalOccurances1, Article1, article..., 12, Article2, article..., 03, Article3, article..., 2Kind regardsChris" |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2004-06-24 : 07:47:35
|
| Group by is your friend.-------Moo. :) |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-24 : 07:48:10
|
| Something Like This:select a.ArticleID, a.Title, a.Article, count(isnull(s.ArticleID, 0)) as TotalOccurancesFROM tblArticle aJOIN tblsentarticles s on a.ArticleID = s.ArticleIDGROUP BY a.ArticleID, a.Title, a.ArticleDuane. |
 |
|
|
cdutoit
Starting Member
1 Post |
Posted - 2004-07-06 : 17:31:48
|
| Thanks Duane!It was exactly what I was looking for! |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-07-07 : 00:05:02
|
| Hey Chris - SA Surname?That was a bit of a delayed response there about 12 days.Duane. |
 |
|
|
|
|
|
|
|