Solved

union query count on word

Posted on 2013-05-19
6
482 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
Comment Utility
the counting doesnt work
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
yes that is correct,
or you could have done it in the other queries "qryword?"
0
 

Author Comment

by:PeterBaileyUk
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now