473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Returning a count of items including zero

Hi,
I have 2 tables, Mail_subject and Mail_Usage.

Mail_Subject contains the subject, body and some other bits of info.
CREATE TABLE [Waterford_MailSubject] (
[ID] [int] NOT NULL ,
[MailSubject] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[MailCategory] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[MailBody] [ntext] COLLATE SQL_Latin1_General_CP1_CS_AS NULL ,
[MailCreateDate] [smalldatetime] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

Mail_Usage records the amount of times a certain mail was sent.
CREATE TABLE [Waterford_MailUsage] (
[ID] [int] NOT NULL ,
[RepScreenName] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[MemberScreenName] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[MailSubject] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[TimeDate] [smalldatetime] NULL ,

) ON [PRIMARY]
GO


They are joined by Subject (not my idea, its a DB ive inherited).

What i need is to get the Mail Subject and the number of times that
Mail was sent. Ive Joined them using an INNER JOIN which gave me a
count of the number of times each one occoured except for Mails that
have not been used. I need to get zero as the count of Mails not
sent. Ive tried a LEFT OUTER JOIN but it didnt work either.

Can someone point out what i need to do ?

Jul 23 '05 #1
1 2324
On 24 May 2005 04:49:33 -0700, garydevstore wrote:
Hi,
I have 2 tables, Mail_subject and Mail_Usage. (snip)What i need is to get the Mail Subject and the number of times that
Mail was sent. Ive Joined them using an INNER JOIN which gave me a
count of the number of times each one occoured except for Mails that
have not been used. I need to get zero as the count of Mails not
sent. Ive tried a LEFT OUTER JOIN but it didnt work either.

Can someone point out what i need to do ?


Hi garydevstore,

Try if this works for you:

SELECT m.MailSubject,
(SELECT COUNT(*)
FROM MailUsage AS u
WHERE u.MailSubject = m.MailSubject)
FROM MailSubject AS m

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bart Nessux | last post by:
New to Python... trying to figure out how to count the objects in a list and then map the count to the objects or convert the list to a dict... I think the latter would be better as I need a number...
8
by: Michael | last post by:
I have this script that works the way I want except for one thing... Once it hits zero it starts to count up and looks like this: -1:0-1:0-1:0-18 with the last number counting up. Can anyone...
1
by: john | last post by:
Relatively new to C coding, so any help would greatly be appreciated. I'm having problems try to return my string array from my parsing function. When I do a printf I am getting the correct value...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
1
by: JonJon | last post by:
I'm currently using .NET Framework 2.0 with WSE 3.0. I've read many articles that DataTables are now serializable and can be passed via web services. However when I have a datatable as my return...
19
by: Adam | last post by:
Hi, I'd like to return an (arbitrary length) string array from a function so that after calling the array I've got a list of strings I can access. After much perusing of the internet I found a...
2
by: BethH | last post by:
According to php.net, mssql_query is supposed to return true when no rows are returned. I'm actually getting an empty resource identifier instead of true. The table is empty, there are no rows...
3
by: waynejr25 | last post by:
can anyone help me add a function that will count the occurance of each word in an input file. here's the code i have so far it counts the number of characters, words, and lines but i need the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.