Solved

SQL: Find missing questions (in a group) in the answers table

Posted on 2011-09-20
2
168 Views
Last Modified: 2012-05-12
I have a questions table with questions that are grouped together.

20 questions belong to group 1
25 questions belong to group 2
18 questions belong to group 3

QuestionID(unique), QuestionGroup, Question

I need to find the questions in each group that are missing in the answers table

QuestionID, UserID, QuestionAnswer

The question I need to answer is: Which questions did the user  NOT answer in each question group. This is indicated by the missing rows in the answers table.

Thanks in advance for any help you can give
0
Comment
Question by:AWEInCA
  • 2
2 Comments
 
LVL 32

Expert Comment

by:ewangoya
ID: 36570673

select QuestionID, Question
from Questiontable
where not exists(select 1 from AnswerTable
                            where AnswerTable.QuestionID = QuestionTable.QuestionID
                            and UserID = 'User you are searching')
0
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 36570677
select QuestionID, QuestionGroup, Question
from Questiontable
where not exists(select 1 from AnswerTable
                            where AnswerTable.QuestionID = QuestionTable.QuestionID
                            and UserID = 'User you are searching')
order by QuestionGroup, QuestionID
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question