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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 right way to do it? finding total number?

Author  Topic 

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2008-12-05 : 14:38:09
I am trying to find the number of publications by subject and type of publication. Is this the correct way to do it?

SELECT COUNT(p.publicationID) AS NumberOfPublications
FROM publication as p
INNER JOIN Booksubjectsjoin as b
ON p.publicationID = b.publicationID
INNER JOIN Subject as s
ON b.subjectID = s.subjectID
INNER JOIN BookType as bt
ON p.typeid = bt.TypeID
GROUP BY s.Subject
order by s.subject, bt.type

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-05 : 14:43:26
quote:
Originally posted by jgonzalez14

I am trying to find the number of publications by subject and type of publication. Is this the correct way to do it?

SELECT s.subject, bt.type
COUNT(p.publicationID) AS NumberOfPublications
FROM publication as p
INNER JOIN Booksubjectsjoin as b
ON p.publicationID = b.publicationID
INNER JOIN Subject as s
ON b.subjectID = s.subjectID
INNER JOIN BookType as bt
ON p.typeid = bt.TypeID
GROUP BY s.Subject,bt.type
order by s.subject, bt.type

Go to Top of Page
   

- Advertisement -