List names from one table whose ID matches entries in another table

时间:2016-02-12 19:40:15

标签: ms-access

I am pretty new to MS Access and a bit at a loss. I am also not very familiar with database jargon, so bear with me.

I have a table with staff names in it (each an individual record and staffID). I have another table with a log, each entry shows at what time a particular staffID took a particular course (course names are stored in another table).

Now I want to make a report that lists each course and the names of the people, who took it.

How do I do that?

2 个答案:

答案 0 :(得分:0)

You need to learn about database joins. Its a fundamental requirement for what you are doing.

SELECT * FROM stafftable s INNER JOIN logtable  l ON l.staffID = s.staffID

will give you a virtual table listing staff details and the course they were on.

You can do this multiple times - so you say the course data is in another table

SELECT s.name As StaffName, c.name As CourseName FROM stafftables  INNER JOIN (logtable l INNER JOIN coursetable c ON l.courseID = c.courseID) ON l.staffID = s.staffID

Will give you a two column table with StaffName and CourseName as the two columns. Note: Access is picky about these joins and you have to put them in brackets like this. Other databases you normally don't have to.

答案 1 :(得分:0)

I think the report wizard could solve your problem.

The wizard walks you through the steps of creating a report and will allow you the opportunity to use more than one table/query in the report. Since you are looking to group by the course, all you would need to do is tell the wizard to do that when it asks you.

This is a straight forward guide on how to use the report wizard: report wizard guide