r said:
Yes, I thought I had the rest of the query figured out, but seems every step
is creating another stumbling point for me.
Let me explain what we're doing, and the db layout. And thank you for your
time. (I'd be happy to send you the db - it is small as it has no live data
in it yet.)
There are 4 tables:
tblShop - (shopID, shopName,shopNumber) - lists shop locations
tblTest - (testID, testName, testFinal) - lists existing test numbers
tblUser - (userID, First, Last, ShopNum) - lists users who've signed up
tblUser2Test - (autonumID, userIDnum, testIDnum, timestamp) - all user test
results
Hi r,
You're on the right track. You basically have 3 entities: Users; Tests;
and Locations (aka Shops). It looks to me like these entities are
related many-to-many. Each User can take one OR MORE tests. Each User
can be tested at one OR MORE locations. Each Test can be offered at one
OR MORE locations. And each location can offer one OR MORE tests.
Since Access cannot represent m:n relationships, you need "resolver"
tables to break up the m:n into 2 1:m relationships. You've already got
one, tblUser2Test. You just need 1 more; let's call it tblTestShop.
tblTestShop will resolve the relationship between Shops & Tests. Put the
pk's from tblTests and tblShops into this resolver as fk's, and give the
TestShop table a pk of its own (say, TestLocID). (Resolver tables can
also contain other information that is pertinent to the unique
combination of fields in a record...in this case, that would be ShopID +
TestID. So TestLoc could contain additional fields if you like:
TestDate; TestProctor; etc..). Finally, put TestLocID into your
User2Test table as an fk, instead of TestID, and include the timestamp &
Test score.
Once your entities and relationships are in place, queries should become
much easier. Although, honestly, this late in the day, I can't think of
a way off the top of my head to do all that you ask in a single gonzo
query. Interspersed below are some suggestions to get you started:
I need a query with the following criteria:
* Top Score on Final from each Shop
SELECT Shops.ShopName, Shops.ShopLoc, Max(UserTest.Score) AS MaxOfScore
FROM Shops INNER JOIN (Tests INNER JOIN (TestLoc INNER JOIN (Users INNER
JOIN UserTest ON Users.UserID = UserTest.UserID) ON TestLoc.TestLocID =
UserTest.TestLocID) ON Tests.TestID = TestLoc.TestID) ON Shops.ShopID =
TestLoc.ShopID
WHERE (((Tests.[Final?])=-1))
GROUP BY Shops.ShopName, Shops.ShopLoc;
* If multiple users with same top score, the one who finished first only
Same top score on same test at same shop? Final score or any score?
* User must have taken a Final (testFinal yes/no) AND another test that is
not a Final
* Need to also display ShopID, ShopName, ShopNumber, UserID, First & Last
Why don't you play around a bit with the modified design & see what you
come up with? If I think of anything else I'll post back.
hth,
LeAnne