473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem with Access SQL Query

Hi folks,

I have the following schema and am using Access 2003:

Enrollments Table
Student (lookup field referencing the Name field in the Students table)
Session (lookup field referencing the ID field in the Sessions table)
ClassesAttended
... (some more fields unnecessary to this discussion)

Students table:
Name
NOFDate
....

Sessions Table
ID
...


Here is my original query...

PARAMETERS NOF Short;
SELECT DISTINCT Students.Name
FROM Students INNER JOIN Enrollments ON Students.Name=Enrollments.Student
WHERE (((Enrollments.ClassesAttended)>=1) AND (Students.NOFDate=[NOF]));

Which does what I need it to by showing unique students by NOFDate.
I'm getting 58 records for one of my sample NOF Dates and that is exactly how many I should have.

However, I need to show those by session as well.
If I add in Enrollments.Session in the SELECT line so it reads...
SELECT DISTINCT Students.Name, Enrollments.Session

Now it doesn't work. I now get all 78 records listed for that NOF Date which gives me duplicate students. What I want is for each Student to only be counted 1x during each NOFDate regardless of how many enrollments are listed.

Please help!!!
Jun 24 '07 #1
1 1085
MMcCarthy
14,534 Expert Mod 8TB
Once you add Sessions you will get the Student Name appearing for each session they attended.

Try this out of curiousity to see what happens.

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS NOF Short;
  2. SELECT Students.Name, Enrollments.Session
  3. FROM Students INNER JOIN Enrollments ON Students.Name=Enrollments.Student
  4. WHERE (((Enrollments.ClassesAttended)>=1) AND (Students.NOFDate=[NOF]))
  5. GROUP BY Students.Name, Enrollments.Session;
Jun 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Juho Saarikko | last post by:
I made a Python script which takes Usenet message bodies from a database, decodes uuencoded contents and inserts them as Large Object into a PostGreSQL database. However, it appears that the to...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
8
by: Alfonso Esteban Gonzalez Sencion | last post by:
I am trying to use Access as a front end for extracting information from an Oracle database. I started using linked tables but I am getting a very curious behaviour. When I consult the linked...
3
by: StBond | last post by:
Hi everyone, I am new to Access and Visual Basic so things my be getting across a bit cloudy. I only started using VB for one week. I am having a little problem with the database that I am...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
39
by: Marcin Zmyslowski | last post by:
Hello all! I have the following problem with MS Access 2003 permissions. I have two users. One is admin and the second one is user who has full permissions to enter modify and read data. I...
1
by: hardik | last post by:
hi friends i need help in this sql query i have table like, id fid __ _____ autonumber text and i am storing values like
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.