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 |
|
doobybug
Starting Member
4 Posts |
Posted - 2009-02-23 : 02:37:21
|
| Hi all, I am a very new student to this stuff, and I need some help while I was experimenting. I have 2 tables called:tblDistributor- DNO (PK)- name- telnoandtblDistributor_Model-DNO(FK)-MNO(FK)I have to find all the distributors who currently distribute our currently distributed products by name. I have written something like this which returns the distributor id and the amount of models that he distributes. How can I get the name as well?SELECT count(*) AS Total_ModelsFROM tblDistributor_Model dm, tblDistributor dGROUP BY dm.DNOHAVING COUNT (*) = (SELECT DISTINCT COUNT(*) FROM tblDistributor) |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2009-02-23 : 02:52:23
|
| --select sum(p),a from @UNIT group by adeclare @tblDistributor table (DNO int,name varchar(100))insert into @tblDistributor values(1,'a')insert into @tblDistributor values(2,'b')SOME THING LIKE THIS.declare @tblDistributor_Model table (DNO int,MNO int)insert into @tblDistributor_Model VALUES (1,1)insert into @tblDistributor_Model VALUES (1,2)insert into @tblDistributor_Model VALUES (1,3)insert into @tblDistributor_Model VALUES (2,1)insert into @tblDistributor_Model VALUES (2,2) SELECT count(*) AS Total_Models,D.NAME FROM @tblDistributor_Model dm JOIN @tblDistributor dON DM.DNO = D.DNOGROUP BY dm.DNO,D.NAMEKarthik |
 |
|
|
doobybug
Starting Member
4 Posts |
Posted - 2009-02-23 : 03:18:38
|
| Thanks a lot!!! Worked perfectly! :) |
 |
|
|
|
|
|
|
|