MikeR said:
I have 2 tables in an Access DB. In the ID table an ID may have 1,2 or 3
rows. The g columns may be either NULL, an F, or a P. I want to select
IDs where none of the rows for that ID contains an F, and find the name
for that ID in another table (sName) which contains IDs and names
ID g1 g2 g3 g4 sem
-----------------------
AA P 1
AA F P 2
AA P 3
BB P 1
CC P 1
CC P 2
CC 3
DD 1
ID stuName
----------------------
AA Bill
BB Joe
CC Mac
DD Mazie
Result set desired:
BB Joe
CC Mac
DD Mazie
TIA, Mike
Assuming the first table is STU_G and the second table is STU_NAMES:
SELECT STU_NAMES.ID, STU_NAMES.STUNAME
FROM STU_NAMES
WHERE STU_NAMES.ID NOT IN
(SELECT STU_G.ID
FROM STU_G
WHERE (((STU_G.G1)="F")) OR (((STU_G.G2)="F")) OR (((STU_G.G3)="F")) OR
(((STU_G.G4)="F"))
);
I would be remiss in my duty to the relational database community if I
did not point out that your first table breaks a cardinal rule of
design: Do not store repeating groups in a table. Such "spreadsheet"
design is difficult to work with in a relational database.
If you are able, restructure the first table so each row represents
exactly one fact. In your situation a fact appears to be one ID, one
"G", and a value for "SEM":
table STU_G_NORMALIZED
======================
PK AUTONUMBER (*)
ID TEXT (+)
G_INDEX NUMBER (+)
SEM NUMBER (+)
G_VALUE TEXT
(*) Suggested as a primary key. Alternatively you could create a unique
index based on the three attributes marked (+). This is done to ensure
duplicate rows are not created.
The data in this new table would look like this:
PK ID G_INDEX SEM G_VALUE
---------------------------------
1 AA 1 1 P
2 AA 1 2 F
3 AA 2 2 P
4 AA 4 3 P
5 BB 1 1 P
....Etc. Notice how you don't need to create "blank" spots.
The new query would look something like
SELECT STU_NAMES.ID, STU_NAMES.STUNAME
FROM STU_NAMES
WHERE STU_NAMES.ID NOT IN
(SELECT STU_G_NORMALIZED.ID
FROM STU_G_NORMALIZED
WHERE STU_G_NORMALIZED.G_VALUE = "F"
);
Notice how much easier it is to find the Fs.
If you plan to use this database for a while, and especially if you plan
to create new ones, it will be well worth your time and effort to study
the topic of "database normalization" (Google with quotes for plenty of
good references).
Hope this helps!