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 |
kwalt
Starting Member
4 Posts |
Posted - 2009-02-17 : 14:15:04
|
I have multiple tables in access. All the tables have the same columns. Im looking to get a count on how many businesses are under each sic code description. For example, how many doctors, lawyers, dentists there are in all my tables. I broke the tables down by counties.My SQL Statement looks like this:SELECT sic_code_description, COUNT(sic) AS "Count SIC"FROM hc_no_indv_docs_lawyersGROUP BY sic_code_description;this works for one table but how do i add the others?I'd appreciate some helpThanks |
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-02-17 : 14:40:42
|
You could use a union statement if you're looking to join them back as 1 result set.select * from mytableUNIONselect * from myothertableUNIONselect * from mythirdtable.Mike"oh, that monkey is going to pay" |
 |
|
kwalt
Starting Member
4 Posts |
Posted - 2009-02-17 : 14:43:30
|
I was looking to get something like this:Sic Code Description Sic CountDoctors 18Lawyers 10Dentists 14 Im trying to find out how many records are under each Sic code description |
 |
|
kwalt
Starting Member
4 Posts |
Posted - 2009-02-17 : 14:46:26
|
i tried union select and i got something like this:sic code description Count Sicdoctors 10doctors 14lawyers 7lawyers 2dentists 12dentists 14 |
 |
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-02-17 : 14:54:07
|
Sorry, I didn't realize you'd have the sam sic in each table. In that case, try wrapping that union statement like thisselect sic,sum(CountSic)from(select sic,count(*)as CountSic from table1Unionselect sic, count(*) as CountSic from table2)Group By SICMike"oh, that monkey is going to pay" |
 |
|
kwalt
Starting Member
4 Posts |
Posted - 2009-02-17 : 16:39:51
|
i tried thisselect sic_code_description, sum(sic_code_description)from(select sic_code_description, count(sic_code_description) as "Number of Records" from hc_no_indv_docs_lawyersUnionselect sic_code_description, count(sic_code_description) as "Number of Records" from pc_no_indv_docs_lawyers)Group By sic_code_description;and access told me "you tried to execute a query that does not include the specified expression sic_code_description as part of an aggregate.im new at this SQL stuff |
 |
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-02-17 : 16:48:11
|
In your select statement outside the unions you are trying to sum sic_code_description. You would need to sum "Number of Records" select sic_code_description, sum(Number of Records)Mike"oh, that monkey is going to pay" |
 |
|
|
|
|
|
|