MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 8th, 2004, 11:59 AM
Uther Uther is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 Uther User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MS Access Query

Hi all, This is my first post and I hope someone will be able to assist.

Situation:
I'm trying to run an MS Access query on a table that has multiple fields that contain similar data

Example:
Field1 Field2
Apples Oranges
Oranges Apples
Apples Apples

All I want to do is count how many times "Apples" appear in this table.

I can do a simple query to obtain the apple count for any one Field but cannot get a total apple count for the entire table.

Any assistance will be greatly appreciated.

Reply With Quote
  #2  
Old December 8th, 2004, 12:43 PM
Vermithrax Vermithrax is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 Vermithrax User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
To summarize, then... You want something similar to this:


Table:
Person Result1 Result2 Result3

Data:
Dave 123 456 789
Jody 123 123 456




And you want to count how many times 123 appears in the table? (3 times, in this case)
Unfortunately, I don't know how to do this, but I'm sure someone does!!!

Is that correct?

Reply With Quote
  #3  
Old December 8th, 2004, 01:15 PM
Uther Uther is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 Uther User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re:

That is correct

Quote:
Originally Posted by Vermithrax
To summarize, then... You want something similar to this:


Table:
Person Result1 Result2 Result3

Data:
Dave 123 456 789
Jody 123 123 456




And you want to count how many times 123 appears in the table? (3 times, in this case)
Unfortunately, I don't know how to do this, but I'm sure someone does!!!

Is that correct?

Reply With Quote
  #4  
Old December 8th, 2004, 03:42 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,653 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 42 m 2 sec
Reputation Power: 981
Code:
select sum(fieldcount) as totalcount
  from (
       select count(*) as fieldcount
         from fruit
        where field1 = 'apples'        
       union all
       select count(*)
         from fruit
        where field2 = 'apples'       
       ) as dt
__________________
r937.com | rudy.ca

Reply With Quote
  #5  
Old December 8th, 2004, 03:48 PM
Uther Uther is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 Uther User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re:

Quote:
Originally Posted by r937
Code:
select sum(fieldcount) as totalcount
  from (
       select count(*) as fieldcount
         from fruit
        where field1 = 'apples'        
       union all
       select count(*)
         from fruit
        where field2 = 'apples'       
       ) as dt


I thought MS Access did not like the SQL select sum(). Maybe I am wrong... I'll give it a try and let you know how I made out.

Thanks

Reply With Quote
  #6  
Old December 8th, 2004, 03:51 PM
Uther Uther is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 Uther User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re:

You are da man/woman!!!! Works perfectly.

TYVM!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > MS Access Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway