Solved

union query count on word

Posted on 2013-05-19
6
524 Views
Last Modified: 2013-05-19
I have the following which works but i want to count the number of words from each field.

SELECT word2, count([word2]) as countword
from qryword2
union
SELECT word3, count([word3]) as countword
from qryword3
union
SELECT word4, count([word4]) as countword
from qryword4
union
SELECT word5, count([word5]) as countword
from qryword5
union
SELECT word6, count([word6]) as countword
from qryword6
union
SELECT word7, count([word7]) as countword 
from qryword7
UNION
SELECT word8, count([word8]) as countword
from qryword8;

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 4
  • 2
6 Comments
 

Author Comment

by:PeterBaileyUk
ID: 39178494
the counting doesnt work
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39178510
SELECT word2 as [Word], count([word2]) as countword
from qryword2
group by word2
union all
SELECT word3 as [Word], count([word3]) as countword
from qryword3
group by word3
union all

etc...
0
 

Author Comment

by:PeterBaileyUk
ID: 39178527
yep worked but i needed sum and to get rid of nulls how do i stop nulls?
SELECT word2, sum([word2]) as countword
from qryword2
where word2 is not null
group by word2
union
SELECT word3, sum([word3]) as countword
from qryword3
where word3 is not null
group by word3
union
SELECT word4, sum([word4]) as countword
from qryword4
where word4 is not null
group by word4; ....
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39178537
yes that is correct,
or you could have done it in the other queries "qryword?"
0
 

Author Comment

by:PeterBaileyUk
ID: 39178542
Yes i did that so no nulls are returned but it says datatype mismatch when i try to use sum?

here is an example output of the sub :
Word2      CountOfWord2
BUSINESS             4
R-DESIGN            17
SE                    15
eeex.PNG
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 39178567
got it thank you:

SELECT word2, sum([countofword2]) as countword2
from qryword2
group by word2
union
SELECT word3, sum([countofword3]) as countword3
from qryword3
group by word3
union
SELECT word4, sum([countofword4]) as countword4
from qryword4
group by word4
union
SELECT word5, sum([countofword5]) as countword5
from qryword5
group by word5
union
SELECT word6, sum([countofword6]) as countword6
from qryword6
group by word6
union
SELECT word7, sum([countofword7]) as countword7
from qryword7
group by word7
union
SELECT word8, sum([countofword8]) as countword8
from qryword8
group by word8;
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question