A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help to select record by checking multiple child items



 
 
Thread Tools Display Modes
  #1  
Old July 4th, 2008, 03:42 PM posted to microsoft.public.access.queries
Renaud_D
external usenet poster
 
Posts: 8
Default Help to select record by checking multiple child items

Hello,

I have a table consisting of student names linked to another one with the
date and status of passed tests (one to many relation).

It does happen that a student passes after the 1st test or needs sometimes
to take it several times before succeeding.

We have something looking like:
Student 1 - date 1st test - result 1st test (failed)
Student 1 - date 2nd test - result 2nd test (passed)
Student 2 - date 1st test - result 1sr test (failed)
Student 2 - date 2nd test - result 2nd test (failed)
Student 2 - date 3rd test - result 3rd test (failed)

I'm trying to design a query that would only return the name of the students
who didn't succeed and consequently exclude the name of those who did pass,
even if after the xth attempt.

In the above example, the query should therefore return:
Student 2
only listed once, for the clarity of the report.

Any advice would be appreciated!

Regards,

Renaud, Brussels
  #2  
Old July 4th, 2008, 05:09 PM posted to microsoft.public.access.queries
[email protected]
external usenet poster
 
Posts: 87
Default Help to select record by checking multiple child items

On Jul 4, 7:42*am, Renaud_D wrote:
Hello,

I have a table consisting of student names linked to another one with the
date and status of passed tests (one to many relation).

It does happen that a student passes after the 1st test or needs sometimes
to take it several times before succeeding.

We have something looking like:
Student 1 - date 1st test - result 1st test (failed)
Student 1 - date 2nd test - result 2nd test (passed)
Student 2 - date 1st test - result 1sr test (failed)
Student 2 - date 2nd test - result 2nd test (failed)
Student 2 - date 3rd test - result 3rd test (failed)

I'm trying to design a query that would only return the name of the students
who didn't succeed and consequently exclude the name of those who did pass,
even if after the xth attempt.

In the above example, the query should therefore return:
* Student 2
only listed once, for the clarity of the report.

Any advice would be appreciated!

Regards,

Renaud, Brussels


Try one of these methods:

SELECT A.StudentID, A.StudentName
from Students as A
where 0 = ( select count(*)
from StudentGrades
where StudentID = A.StudentID
and Result = 'Passed' )

or

SELECT A.StudentID, A.StudentName
from Students as A
where not exists
( select 'true'
from StudentGrades
where StudentID = A.StudentID
and Result = 'Passed' )


or

SELECT A.StudentID, A.StudentName
from Students as A LEFT JOIN StudentGrades as B on A.StudentID =
B.StudentID
where B.Result = 'Passed' and B.StudentID is null
  #3  
Old July 4th, 2008, 05:52 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Help to select record by checking multiple child items

Renaud_D wrote:
I have a table consisting of student names linked to another one with the
date and status of passed tests (one to many relation).

It does happen that a student passes after the 1st test or needs sometimes
to take it several times before succeeding.

We have something looking like:
Student 1 - date 1st test - result 1st test (failed)
Student 1 - date 2nd test - result 2nd test (passed)
Student 2 - date 1st test - result 1sr test (failed)
Student 2 - date 2nd test - result 2nd test (failed)
Student 2 - date 3rd test - result 3rd test (failed)

I'm trying to design a query that would only return the name of the students
who didn't succeed and consequently exclude the name of those who did pass,
even if after the xth attempt.

In the above example, the query should therefore return:
Student 2
only listed once, for the clarity of the report.



SELECT DISTINCT student
FROM table
WHERE Not Exists (SELECT X.student
FROM table As X
WHERE X.result = "passed")

--
Marsh
MVP [MS Access]
 




Thread Tools
Display Modes

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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:35 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.