?
Solved

Query Syntax - Returning all of 1 table and part of the other

Posted on 2011-05-10
4
Medium Priority
?
230 Views
Last Modified: 2012-05-11
Hi All,

I have the following SQL in MS Access which at the moment returns all the questions and answer records that have been answered based on a particular userID.

What I need to be able to ahieve is to change this query so that all questions are returned whether that UserID has provided an answer or not. This will show me the questions/answers and the questions the user has yet to answer...

This is what it produces now...

quizID    question       AnswerText    userID
1             Gender        Male                1
3             Nationality   British              1

This is what I would like it to produce...

quizID    question       AnswerText    userID
1             Gender        Male                1
2             Sugar          NULL                  NULL
3             Nationality   British              1


Can anyone help with my syntax?

Many thanks,

Rit
SELECT 
	tblQuiz.quizID, 
	tblQuiz.question, 
	tblAnswers.AnswerText, 
	tblAnswers.userID
	
FROM tblQuiz LEFT JOIN tblAnswers ON tblQuiz.quizID = tblAnswers.quizID

WHERE (((tblAnswers.userID)=[paramMyID])

Open in new window

0
Comment
Question by:rito1
  • 2
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35728491
you where close:
SELECT 
	tblQuiz.quizID, 
	tblQuiz.question, 
	tblAnswers.AnswerText, 
	tblAnswers.userID
	
FROM tblQuiz LEFT JOIN tblAnswers ON tblQuiz.quizID = tblAnswers.quizID AND tblAnswers.userID =[paramMyID]

Open in new window


with the condition in the LEFT JOIN it should work, otherwise you made it a INNER JOIN implicitly

0
 
LVL 1

Author Comment

by:rito1
ID: 35728804
Thanks angelll,

I am trying your syntax but I get the error JOIN expression not supported.

I am executing this query within MS Access SQL View.

Rit
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35729479
ms acces:s:
SELECT 
        tblQuiz.quizID, 
        tblQuiz.question, 
        tblAnswers.AnswerText, 
        tblAnswers.userID
        
FROM tblQuiz LEFT OUTER JOIN tblAnswers ON (tblQuiz.quizID = tblAnswers.quizID AND tblAnswers.userID =[paramMyID] )

Open in new window

0
 
LVL 1

Author Closing Comment

by:rito1
ID: 35729687
angelll,

I seemed to resolve it by adding (OR (tblAnswers.quizID) IS NULL).

I could kick myself sometimes :-)

Thanks for the support as always.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

621 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