473,320 Members | 2,110 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,320 software developers and data experts.

Multi-table lookups

Hi. I'm trying to create a query that pulls information
from 3 seperate tables. Here's how I want it to work:

User is prompted for SSN

Table 1:
SSN
Name
Gender

Table 2:
SSN
Age
Repetitions

Table 3:
Gender
Age
Repetitions
Score

After the user inputs the SSN, I need to look up the score
from table 3 based on age and repetitions from table 2. I
thought DLookUp() was the way to do it, but (1) I've been
having problems with it and (2) I've read that it isn't
the most effective way to lookup that kind of information.

Can anyone help me? I can create this query either
through QBE or SQL.

Thanks

Rob Mazur
Nov 12 '05 #1
8 2567
TC
Rob, no-one can reliably answer questions like this, unless you state the
primary key of each table involved.

HTH,
TC
"Rob Mazur" <rp*****@hotmail.com> wrote in message
news:2d**************************@posting.google.c om...
Hi. I'm trying to create a query that pulls information
from 3 seperate tables. Here's how I want it to work:

User is prompted for SSN

Table 1:
SSN
Name
Gender

Table 2:
SSN
Age
Repetitions

Table 3:
Gender
Age
Repetitions
Score

After the user inputs the SSN, I need to look up the score
from table 3 based on age and repetitions from table 2. I
thought DLookUp() was the way to do it, but (1) I've been
having problems with it and (2) I've read that it isn't
the most effective way to lookup that kind of information.

Can anyone help me? I can create this query either
through QBE or SQL.

Thanks

Rob Mazur

Nov 12 '05 #2
Why do you have/need 3 tables? Can't Tables 1 and 2 be merged? How
are they related (1-1, 1-M?) What are you *really* trying to achieve
here? What's in the "repetitions" table? Rules?

Don't know about anyone else, but I'd certainly need more information
before I could even guess what's going on. My initial guess is that
you need to normalize, but I can't even tell that without further
information about what you're trying to model.
Nov 12 '05 #3
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf*************************@posting.google.c om>...
Why do you have/need 3 tables? Can't Tables 1 and 2 be merged? How
are they related (1-1, 1-M?) What are you *really* trying to achieve
here? What's in the "repetitions" table? Rules?

Don't know about anyone else, but I'd certainly need more information
before I could even guess what's going on. My initial guess is that
you need to normalize, but I can't even tell that without further
information about what you're trying to model.


Okay, here's the scoop. I have 3 tables: (1) Solider Information
(Name, Gender, SSN[Primary Key], Unit), (2) APFT Record (SSN, Rank,
Age, PTTestDate, PURaw, SURaw, 2MileRunRaw, etc), (3) ScoreLookup
(Age, PURaw, PUScore, SURaw, 2MileRunRaw, 2MileRunScore).

The thought here was to have individual tables for Solider
Information, PT Test scores and the ScoreLookup table would contain
the Raw score (repetitions) to actual score. For example, a 19 year
old Male who did 40 push ups has a score of 57. So, the lookup needs
to be based on age, gender and raw score.

I felt from a management standpoint having this information in
seperate tables would be easier. Honestly, I'm not sure if that's the
right/best way to accomplish this task. Since PT Tests are held at a
minimum of every 6 months, there would be at least 2 entries in the
APFT table (possibly more depending on length of stay at a duty
station). I couldn't use the [APFT Record].[SSN] as a primary key,
because it wouldn't allow duplicate entries (unless my relationship
was screwed up.)

Thanks for your help on this.

Rob
Nov 12 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd change the table designs (the below CREATE TABLE statements use
the ANSI/JET DDL):

Table Units is a lookup table of Unit names associated w/ ID numbers
that other tables will use instead of the Unit name.

CREATE TABLE Units (
Unit COUNTER NOT NULL , -- Counter is JET AutoNumber
UnitName VARCHAR(35) NOT NULL PRIMARY KEY,
CONSTRAINT idxUnit UNIQUE (Unit)
)

Personal info (Age & Rank) particular to one individual (solider)
usually should be in the same table instead of in many tables
(Soliders & PTTests).

CREATE TABLE Soliders (
SoliderID COUNTER NOT NULL ,
SSN VARCHAR(9) NOT NULL PRIMARY KEY,
LastName VARCHAR(25) NOT NULL,
FirstName VARCHAR(20) ,
Rank VARCHAR(5) NOT NULL ,
Age INTEGER ,
Unit INTEGER NOT NULL REFERENCES Units,
CONSTRAINT idxSoliderID UNIQUE (SoliderID)
)

Table PTTests is another lookup table that will be used like the Units
table. This table helps normalize the APFT and ScoreLookup tables -
you don't have to have a column for each test.

CREATE TABLE PTTests (
TestID COUNTER NOT NULL CONSTRAINT idxTestID UNIQUE ,
TestName VARCHAR(30) NOT NULL PRIMARY KEY
)

PTTests data would look like this:

TestID TestName
- ------ --------
1 PURaw
2 PUScore
3 SURaw
4 2MileRunRaw
.... etc. ...

I'm not sure about the "raw" and "score" test names. These may be 2
different things. IOW, the Tests may in fact be PU, SU, 2MileRun,
etc., and Raw is a datum that is independent of the solider's score -
i.e., the Raw value is a value that the solider's test score is
compared against. Correct? Anyway, I made the remaining tables using
that assumption.

[APFT = Army Physical Fitness Test?]

This table holds each solider's test score, per test date. This is
the table that will have the most "work" (data entry). SoliderID
refers to table Soliders - there is where you'll get the solider's age
& rank. The primary key allows only one type of test per solider per
date.

CREATE TABLE APFT (
SoliderID INTEGER NOT NULL REFERENCES Soliders ,
PTTestDate DATETIME NOT NULL ,
TestID INTEGER NOT NULL REFERENCES PTTests ,
Score INTEGER NOT NULL ,
CONSTRAINT PK_APFT PRIMARY KEY (SoliderID, PTTestDate, TestID)
)

CREATE TABLE ScoreLookup (
TestID INTEGER NOT NULL REFERENCES PTTests ,
Age INTEGER NOT NULL ,
Raw INTEGER NOT NULL PRIMARY KEY ,
CONSTRAINT PK_ScoreLookup PRIMARY KEY (TestID, Age, Raw)
)

I'm not sure about this table - I'm assuming it holds data about what
the aveage/lowest (?) "raw" score is for each age group, per test.
That's the way I set it up.

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP8OVE4echKqOuFEgEQLrHQCeKhokd+HLn6eMr4+jMBhAmj U295QAoNrI
e4CmBe3NIBPQQUgKx8nmsO0y
=ZNJC
-----END PGP SIGNATURE-----
Rob Mazur wrote:
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf*************************@posting.google.c om>...
Why do you have/need 3 tables? Can't Tables 1 and 2 be merged? How
are they related (1-1, 1-M?) What are you *really* trying to achieve
here? What's in the "repetitions" table? Rules?

Don't know about anyone else, but I'd certainly need more information
before I could even guess what's going on. My initial guess is that
you need to normalize, but I can't even tell that without further
information about what you're trying to model.

Okay, here's the scoop. I have 3 tables: (1) Solider Information
(Name, Gender, SSN[Primary Key], Unit), (2) APFT Record (SSN, Rank,
Age, PTTestDate, PURaw, SURaw, 2MileRunRaw, etc), (3) ScoreLookup
(Age, PURaw, PUScore, SURaw, 2MileRunRaw, 2MileRunScore).

The thought here was to have individual tables for Solider
Information, PT Test scores and the ScoreLookup table would contain
the Raw score (repetitions) to actual score. For example, a 19 year
old Male who did 40 push ups has a score of 57. So, the lookup needs
to be based on age, gender and raw score.

I felt from a management standpoint having this information in
seperate tables would be easier. Honestly, I'm not sure if that's the
right/best way to accomplish this task. Since PT Tests are held at a
minimum of every 6 months, there would be at least 2 entries in the
APFT table (possibly more depending on length of stay at a duty
station). I couldn't use the [APFT Record].[SSN] as a primary key,
because it wouldn't allow duplicate entries (unless my relationship
was screwed up.)

Thanks for your help on this.

Rob


Nov 12 '05 #5
TC

"Rob Mazur" <rp*****@hotmail.com> wrote in message
news:2d**************************@posting.google.c om...
pi********@hotmail.com (Pieter Linden) wrote in message

news:<bf*************************@posting.google.c om>...
Why do you have/need 3 tables? Can't Tables 1 and 2 be merged? How
are they related (1-1, 1-M?) What are you *really* trying to achieve
here? What's in the "repetitions" table? Rules?

Don't know about anyone else, but I'd certainly need more information
before I could even guess what's going on. My initial guess is that
you need to normalize, but I can't even tell that without further
information about what you're trying to model.


Okay, here's the scoop. I have 3 tables: (1) Solider Information
(Name, Gender, SSN[Primary Key], Unit), (2) APFT Record (SSN, Rank,
Age, PTTestDate, PURaw, SURaw, 2MileRunRaw, etc), (3) ScoreLookup
(Age, PURaw, PUScore, SURaw, 2MileRunRaw, 2MileRunScore).


(snip)

You're still not giving the primary key for each table. Believe me, this
will cause you grief in the long run.

TC

Nov 12 '05 #6
"TC" <a@b.c.d> wrote in message news:<1069815786.72334@teuthos>...
"Rob Mazur" <rp*****@hotmail.com> wrote in message
news:2d**************************@posting.google.c om...
pi********@hotmail.com (Pieter Linden) wrote in message

news:<bf*************************@posting.google.c om>...
Why do you have/need 3 tables? Can't Tables 1 and 2 be merged? How
are they related (1-1, 1-M?) What are you *really* trying to achieve
here? What's in the "repetitions" table? Rules?

Don't know about anyone else, but I'd certainly need more information
before I could even guess what's going on. My initial guess is that
you need to normalize, but I can't even tell that without further
information about what you're trying to model.


Okay, here's the scoop. I have 3 tables: (1) Solider Information
(Name, Gender, SSN[Primary Key], Unit), (2) APFT Record (SSN, Rank,
Age, PTTestDate, PURaw, SURaw, 2MileRunRaw, etc), (3) ScoreLookup
(Age, PURaw, PUScore, SURaw, 2MileRunRaw, 2MileRunScore).


(snip)

You're still not giving the primary key for each table. Believe me, this
will cause you grief in the long run.

TC


TC:

That's part of the problem. I've tried a couple of different primary
keys with no success. Any suggestions on that?

Also, it was suggested the the Solider Information and APFT Record
tables be combined. Good/Bad idea?

Thanks for the help so far.

Rob
Nov 12 '05 #7

"Rob Mazur" <rp*****@hotmail.com> wrote in message
news:2d**************************@posting.google.c om...
"TC" <a@b.c.d> wrote in message news:<1069815786.72334@teuthos>...
"Rob Mazur" <rp*****@hotmail.com> wrote in message
news:2d**************************@posting.google.c om...
pi********@hotmail.com (Pieter Linden) wrote in message

news:<bf*************************@posting.google.c om>...
> Why do you have/need 3 tables? Can't Tables 1 and 2 be merged? How
> are they related (1-1, 1-M?) What are you *really* trying to achieve > here? What's in the "repetitions" table? Rules?
>
> Don't know about anyone else, but I'd certainly need more information > before I could even guess what's going on. My initial guess is that
> you need to normalize, but I can't even tell that without further
> information about what you're trying to model.

Okay, here's the scoop. I have 3 tables: (1) Solider Information
(Name, Gender, SSN[Primary Key], Unit), (2) APFT Record (SSN, Rank,
Age, PTTestDate, PURaw, SURaw, 2MileRunRaw, etc), (3) ScoreLookup
(Age, PURaw, PUScore, SURaw, 2MileRunRaw, 2MileRunScore).


(snip)

You're still not giving the primary key for each table. Believe me, this
will cause you grief in the long run.

TC


TC:

That's part of the problem. I've tried a couple of different primary
keys with no success. Any suggestions on that?

Also, it was suggested the the Solider Information and APFT Record
tables be combined. Good/Bad idea?

Thanks for the help so far.

Rob

Rob, post the fields of the specific table in question, & a brief
description of what a single row in that table, represents. Something along
the following lines:

tblPerson - one row for each person known to the system.
surname - person's surname
DOB - person's date of birth.
etc.

Then we can help you find the primary key.

Primary keys are a fundamentl component of a relational database management
system like Access. Nothing else will work properly - everything else will
go wrong - if you don't have the right primary keys.

HTH,
TC

Nov 12 '05 #8
">
Rob, post the fields of the specific table in question, & a brief
description of what a single row in that table, represents. Something along
the following lines:

tblPerson - one row for each person known to the system.
surname - person's surname
DOB - person's date of birth.
etc.

Then we can help you find the primary key.

Primary keys are a fundamentl component of a relational database management
system like Access. Nothing else will work properly - everything else will
go wrong - if you don't have the right primary keys.

HTH,
TC


TC:

I apologize for not posting a reply sooner, it's been busy around
here. I willpost those tables/fields tomorrow AM.

Thanks again
Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.