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 3934204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:41:21+00:00 2026-05-19T23:41:21+00:00

I have an exam database, with 4 tables: users, answers, questions and subjects. user

  • 0

I have an exam database, with 4 tables: users, answers, questions and subjects.

user table
U_id | name

subjects table
S_id | Subject

questions table
Q_id | S_id | question | Correct 

answers table
U_id | Q_id  | answers

I need to find the number of correct answer per subject, per user.

My query

select  U_id,questions.S_id ,count(Q_id) 
from answers inner join questions  on  questions.q_id = answers.q_id
where questions.Correct  = answers.answer
group by answers.U_id,questions.S_id

result:
1 | s1 | 2
1 | s2 | 3
1 | s3 | 1
2 | s1 | 1
2 | s2 | 1

That gives me the number of correct answer per subject, but if the user doesn’t have a correct answer the S_id is not display, i need to display those with 0.

The result I need is

result:
1 | s1 | 2
1 | s2 | 3
1 | s3 | 1
2 | s1 | 1
2 | s2 | 1
2 | s3 | 0

Note: I´m using MySQL, but a MS SQL server answer is also fine.

  • 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-19T23:41:21+00:00Added an answer on May 19, 2026 at 11:41 pm
    select u.U_id, q.S_id, count(a.q_id) 
    from users u
    cross join questions q
    left join answers a on q.q_id = a.q_id and u.u_id = a.u_id and q.Correct = a.answer
    group by u.U_id, q.S_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following database, the first table users is a table containing my
I have a practice exam for my compilers course with the following questions that
Hello i have an Entity Exam @Id @GeneratedValue(strategy=GenerationType.TABLE) private Long id; ..... ...... @ManyToMany
I have two Models, one that has the name Exam and one that has
I have two arrays: array testAnswer holds answers to a exam and array inputAnswers
I'm pretty close to an exam where I have to answer some questions about
this is really hard question. I have an exam. And questions will be like
I have database of students.. I have generated Student Exam Report with Marks and
I have two mySQL tables in my database Training: +-------------+------------+------------+------------+-...-+------------+ | Training_ID | 09-06-2012
I have the following database db: exam_2011 tables: score_01, score_02, score_03.....score_12 db: exam_2012 tables:

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.