Question : Query a database for certain records

Hi everyone

I have attached a spreadsheet which shows example information from my database. The information is to do with register marking for each student.  If a register isnt marked it will not be stored in the database.

What I have been asked to do is report which lectures have marked the register for another lecturer.   What I want to do is check each record and see if the module staff num is the same as the register staff num if not then I know that a different lecturer other than the actual module lecturer has marked the register for that particular week.  This bit I can do but my problem is if there is 6 students in the class I am getting the output 6 times.  Example in the spreadsheet row 10 and row 39 we can see that on week 11 Chris mullan marked the register for John doherty who is the module lecturer.  It is shown on row 10 and row 39 as there are two different students I would only like to show this record once as the reigster applies to the one class (defined by the same register id and register group).

Week no - this shows the week number that the register was marked so if a stand in lecturer  marked the register in week 10 and week 20 then I want to show the details twice as they are different weeks

Register id and group - Unique code to identify the register for that class, each different class with have a different register id and group

Output that I need from the spreadsheet is shown in sheet 2

Any help really appreciated and any clarifications please ask

This is not homework just a very tricky work question

Thanks in advance
Attachments:
 
example data
 

Answer : Query a database for certain records

You're welcome - glad to help!

The first select, within the parentheses, gives you the rows that you want, but you had needed the additional attributes which would require joining back to your original table.  To simplify the overall final query, I decided to put that first result set into a temp named result set by using the WITH clause.  I named that temp result set "Lecturers".  I can join to that Lecturers result set like I would any other table in the overall final query.
Your original table is joined to the temp result set on the columns that could be used as a key along with the MIN StudentId to filter out the extras.
Random Solutions  
 
programming4us programming4us