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

  • SEARCH
  • Home
  • 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 9149411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:28:23+00:00 2026-06-17T11:28:23+00:00

I have a database sample below: Session Table: SessionId (PK auto) SessionName 1 SODJW

  • 0

I have a database sample below:

Session Table:

SessionId (PK auto)  SessionName
1                    SODJW

Question Table:

QuestionId (PK auto)  QuestionContent  SessionId (FK) refer to Session
1                     Blah             1   
2                     Blah Blah        1
3                     Blah Blah Blah   1

Penalty_Marks Table:

PenaltyAnswerId  PenaltyMarks  QuestionId (FK) refer to Question
1                1             1
2                0             1
3                1             2
4                2             3
5                2             3

Now I want to Perform an SQL which counts the PenaltyMarks for a Session. So for that to happen, we need to know which QuestionId belongs to the SessionId and then count the marks.

My question is how can the SQL for this be written to be able to find the QuestionId‘s within the SessionId so then we can count the penalty marks? Reason I am asking this is because it is giving me incorrect count value.

My attempt:

SELECT COUNT(PenaltyMarks)
FROM Session s
INNER JOIN Question q ON s.SessionId = q.SessionId
INNER JOIN Penalty_Marks pm ON q.QuestionId = pm.QuestionId
WHERE s.SessionId = 1; 
  • 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-06-17T11:28:24+00:00Added an answer on June 17, 2026 at 11:28 am

    Your query returns number of rows, not the total Count of penalty marks. Also you said that you need to view each session’s question with the total penalty marks so you’ll have to group by session id and question id.

    SELECT s.SessionId,q.QuestionId,SUM(pm.PenaltyMarks)
        FROM Session s
        INNER JOIN Question q ON s.SessionId = q.SessionId
        INNER JOIN Penalty_Marks pm ON q.QuestionId = pm.QuestionId
        GROUP BY s.SessionId,q.QuestionId
    

    SQL Fiddle Demo

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

Sidebar

Related Questions

Suppose I have this database table (some sample code below) that stores the relationship
I have a table stored in database with below sample data: Name City Age
I have a database with sample data represented by Table 1 below. How do
i have table with name sample in my database it has threecolumns namely words,D1,D2
I have a sample database like below, and I want to display only the
I have installed a sample database, specifically Northwind from http://msdn.microsoft.com/en-us/library/8b6y4c7s.aspx . After installing the
I have a sample page that uses 2 PHP files and a MySql database,
Say you have a string 3.4564. A sample set in the database has these
I have simple database - one table with 6 collumns. 3 of them i
I have a simple database named customer with a single table data.I want to

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.