Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 17th, 2002, 11:01 AM
bapolis bapolis is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 257 bapolis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 56 sec
Reputation Power: 7
Access Query problem

Hello,

I'm using Access 2000 and I have a table with the following fields:

- id
- name

In my query, I want to display the values of both of these fields for each row, but also display how many times each unique name appears. For example, how many rows have the name "Bob". To do this, I'm using the COUNT function, but it's not working! Here is my SQL statement:

SELECT DISTINCT id, name, COUNT(bid) AS total FROM people;

When I run this query, I get the following error:

"You tried to execute a query that does not include the specified expression 'id' as a part of an aggregate function

Can anyone help me with this?

Reply With Quote
  #2  
Old July 17th, 2002, 02:54 PM
NoXcuz's Avatar
NoXcuz NoXcuz is offline
Wiking
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Sep 2000
Location: Sweden
Posts: 3,608 NoXcuz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 49 m 27 sec
Reputation Power: 11
You can't use an aggregate function and list details at the same time. Your COUNT(bid) will return 1 for every row (id, name), and that's not what you want is it? Besides that, you need to use GROUP BY when you use COUNT(). I take it as id and name are unique, so what you might want to do is something like this:
SELECT name, COUNT(bid) AS total FROM people GROUP BY name

//NoXcuz
__________________
UN*X is sexy!
who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Access Query problem


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 2 hosted by Hostway