Hello everyone! I am new to SQL and have given myself a 3 Day crash course! I apologize for my lack of knowledge. A project was assigned to me for work and so now I need to get it done.
I am running SQL SERVER 2008. I have one Database. It is called "HomeHealth ". It has 3 Tables.
1.HomeCareAgenc ies (Holds the Agency Information such as name, address, phone, as well as an ID that is called Mnemonic in the table.
2.MoCounties (It holds, County Names, Services Offered and also has the Mnemonic field. This table is for 1 State.
3. ILCounties (Same as MoCounties but is for a second state.
Now, I need to be able to run a query that will give me all fields from HomeCareAgencie s, MoCounties County Name and Services as well as ILCounties County Name and Services.
Seems like it would be easy and in fact I have accomplished this. However, It creates a result of about 9,000 rows because if one home Care Agency is in multiple counties in both states and offers multiple services it displays it in individual lines. I need it to have one line for the Agency to include all of the MoCounties, IlCounties and all services that it provides.
I tried using a Count(*)AS Rank in my query but it flakes out.
This Query works great:
_______________ _______________ _______________ ___
_______________ _______________ _______________ _____
However it doesn't include the Data from the HomeCareAgencie s table.
I am sorry for the length of this. Any and ALL suggestions are extremely appreciated!! Thank you sincerely.
I am running SQL SERVER 2008. I have one Database. It is called "HomeHealth ". It has 3 Tables.
1.HomeCareAgenc ies (Holds the Agency Information such as name, address, phone, as well as an ID that is called Mnemonic in the table.
2.MoCounties (It holds, County Names, Services Offered and also has the Mnemonic field. This table is for 1 State.
3. ILCounties (Same as MoCounties but is for a second state.
Now, I need to be able to run a query that will give me all fields from HomeCareAgencie s, MoCounties County Name and Services as well as ILCounties County Name and Services.
Seems like it would be easy and in fact I have accomplished this. However, It creates a result of about 9,000 rows because if one home Care Agency is in multiple counties in both states and offers multiple services it displays it in individual lines. I need it to have one line for the Agency to include all of the MoCounties, IlCounties and all services that it provides.
I tried using a Count(*)AS Rank in my query but it flakes out.
This Query works great:
_______________ _______________ _______________ ___
Code:
SELECT Services, County,
COUNT(*) AS Rank
FROM ILCounties AS IlCounties
INNER JOIN HomeCareAgencies AS HomeCareAgencies
ON ILCounties.Mnemonic = HomeCareAgencies.Mnemonic
AND ILCounties.Mnemonic <= HomeCareAgencies.Mnemonic
GROUP BY Services,
County
However it doesn't include the Data from the HomeCareAgencie s table.
I am sorry for the length of this. Any and ALL suggestions are extremely appreciated!! Thank you sincerely.
Comment