i have the following query which gives me the correct result as follows:
SELECT *
FROM dbo.QAA
INNER JOIN dbo.QA
ON QAA.ID = QA.ID
INNER JOIN dbo.Q
ON Q.QID = QA.QID
INNER JOIN dbo.V
ON V.VID = QAA.VID
Where
Q.QID = 1111
and V.SID = 4785
and V.VID = QAA.VID
and QA.TypeID = 4 and code <> '75785'
which gives me back the following table
Answer | Code | User
Apples |45879 |958-dfdf255-sdfsdf
Banana |45214 |958-dfdf255-sdfsdf
Carrot |74896 |958-dfdf255-sdfsdf
as you can see i get 3 different answers above. Now i needed to add this query as a subquery as follows
SELECT Name
, FirstName
,table.code
(SELECT Top 1
QAA.Answer
FROM dbo.QAA
INNER JOIN dbo.QA
ON QAA.ID = QA.ID
INNER JOIN dbo.Q
ON Q.QID = QA.QID
INNER JOIN dbo.V
ON V.VID = QAA.VID
Where
Q.QID = 1111
and V.SID = 4785
and V.VID = QAA.VID
and QA.TypeID = 4 and code <> '75785') AS AnswerComment
from table
where table.code=5
but now i dont get all the answers back, this is how the table looks
AnswerComment | code | Name | firstname
Apples |45879 |958-dfdf255-sdfsdf | Jane
Apples |45214 |958-dfdf255-sdfsdf |Jane
Apples |74896 |958-dfdf255-sdfsdf |Jane
my question is in the subquery how do i return all of the answercomments?
I know Top 1 will only retrieve the first record its just an example to show. i also tried
select max (QAA.Answer)
but this also only returns one value back