TotalNewbie
TotalNewbie

Reputation: 1024

simple SQL Statement confusion

apologies I know this must be extremely extremely simple, but I am completely new to this and I am struggling on an simple select SQL Query, I have two tables as seen below.

table 1 quiz
QuizID, ....etc.
Int         

table 2 useranswers
UserAnswersID, QuizID, 
Int             Int         

I simply wish to select the QuizID from the first table using the UserAnswersID from the second table. I tried writing the following with no luck:

SELECT A.QuizID
FROM quiz Q, useranswers UA
WHERE UA.UserAnswersID = (**int**)

Upvotes: 0

Views: 45

Answers (2)

G one
G one

Reputation: 2729

SELECT Q.QuizID
FROM quiz Q inner join useranswers UA
on UA.UserAnswersID = Q.QuizID

Upvotes: 1

Abdul Manaf
Abdul Manaf

Reputation: 4888

SELECT 
    Q.QuizID
FROM
    quiz Q,
    useranswers UA
WHERE
    UA.UserAnswersID = Q.QuizID;

Or you can use JOIN

SELECT 
    Q.QuizID
FROM
    quiz Q
        JOIN
    useranswers UA ON UA.UserAnswersID = Q.QuizID;

Upvotes: 2

Related Questions