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 |
|
Jay99
468 Posts |
Posted - 2001-03-28 : 14:54:03
|
| CREATE TABLE ContactMaster( intContactID INTEGER IDENTITY(100,1) NOT NULL, vcName VARCHAR(75) NOT NULL,...blah,blah,blah... vcCategory VARCHAR(20), bIsActive BIT)CREATE TABLE ContactCategory( vcCategory VARCHAR(20) NOT NULL)GOALTER TABLE ContactMaster ADD CONSTRAINT ContactMastervcCategoryFK FOREIGN KEY (vcCategory) REFERENCES ContactCategory(vcCategory)GOCREATE NONCLUSTERED INDEX vcCategoryIDX ON ContactMaster(vcCategory)GOI want to return a list of all available vcCategory from ContactCategory and the count of how many contacts are associated with that category. I have this:SELECT cc.vcCategory, (SELECT COUNT(*) FROM ContactMaster cm WHERE cm.vcCategory = cc.vcCategory) as 'intCount'FROM ContactCategory ccORDER BY vcCategory ASCThis works, but do you have a better idea?ThxJay |
|
|
|
|
|