Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6744637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:06:27+00:00 2026-05-26T12:06:27+00:00

Below is my query: $query = SELECT gr.SessionId, t.TeacherUsername, s.ModuleId, m.ModuleName, st.CourseId, st.Year, st.StudentUsername,

  • 0

Below is my query:

$query = "
          SELECT gr.SessionId, t.TeacherUsername, s.ModuleId, m.ModuleName, 
      st.CourseId, st.Year, st.StudentUsername, gr.Mark, gr.Grade
      FROM Teacher t
          INNER JOIN Session s ON t.TeacherId = s.TeacherId
          JOIN Grade_Report gr ON s.SessionId = gr.SessionId
          JOIN Student st ON gr.StudentId = st.StudentId
          JOIN Course c ON st.CourseId = c.CourseId
          JOIN Course_Module cm ON c.CourseId = cm.CourseId
          JOIN Module m ON cm.ModuleId = m.ModuleId
          WHERE
            ('".mysql_real_escape_string($sessionid)."' = '' OR gr.SessionId = '".mysql_real_escape_string($sessionid)."')
          ";

Below is what is query is outputting:

Session ID  TeacherUsername Module Number   ModuleName  Course ID   Year    Student Username    Mark    Grade
AAA            m.prigmore   CHT2520        Web Program  INFO102      1      u1231231            69       B
AAA            m.prigmore   CHT2520        Database     INFO102      1      u1231231            69       B
AAA            m.prigmore   CHT2520        Web Program  INFO102      2      u0833421            71       A
AAA            m.prigmore   CHT2520        Database     INFO102      2      u0833421            71       A

If you look carefully what is happening is that in the Course_Module table which I have used to JOIN the Course table and Module table, there are 2 modules for the course ‘INFO102’. Because of this it is showing 4 rows as it is trying to show two Modules Names (which comes from module table) for a Session for each student. This is incorrect as it should only link to the module which belongs to the session which should be ‘Web Program’, not ‘Database’ (This is because ModuleNumber CHT2520 = ‘Web Program’ in Module Table).

Below is what it should output:

Session ID  TeacherUsername Module Number   ModuleName  Course ID   Year    Student Username    Mark    Grade
    AAA            m.prigmore   CHT2520        Web Program  INFO102      1      u1231231            69       B
    AAA            m.prigmore   CHT2520        Web Program  INFO102      2      u0833421            71       A

So how can I get rid of the rows which says ‘Database’ under ‘ModuleName’ and that Module Number only matches with the correct Module Name?

Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:06:28+00:00Added an answer on May 26, 2026 at 12:06 pm

    The problem is that you are getting ModuleNumber from the Session table and ModuleName from the Module table. Your query says, “for this session, get all grade reports, and for those grade reports, get all students, and for all students, get all courses, and for all courses, get all course-module links, and for all course-module links, get all modules.”

    That’s why you see all modules listed for that combination of grade report, student, course and module. You could add “AND s.ModuleId = m.ModuleId” and that should fix it. I presume you have ModuleId in the session table, if you also have ModuleNumber. And if so, you don’t need ModuleNumber in your Session table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below sql query: select @table1 as DataState, * from (select *
What does the below query explain? SELECT * FROM `jos_menu` WHERE (id = 69
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
My query is like below (not working correctly) SELECT RentACar.dbo.Car.car_id as clm_CAR_ID, RentACar.dbo.Car_Image.car_image_url as
I am trying to run the following script (unsuccessfully): $variables = $db->query(SELECT * FROM
I am creating a chunk of HTML/JavaScript with the below code: $result = mysql_query(SELECT
In the below query even position and category_id conditions are met there is no
I have the below query, which basically it retrieves the 5 top most books
I have below query I am trying to show message 'No SubSource for this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.