简体   繁体   中英

SQL: Adding column from table B to table A

I have 2 tables in my database:

http://bildr.no/view/SnIzL1Z2

And I want the following output:

http://bildr.no/view/REFDamZn

I have tried with innerjoins, but then I'm returned way to many rows.

Does someone has a solution for this?

Thx!

Select ta.*,tq.Question
From TblAnswers ta
Inner Join TblQuestion tq
  On ta.QuestionId=tq.QuestionId

Please try using INNER JOIN

SELECT DISTINCT
    A.ID,
    A.SurveyID,
    A.PersonID,
    A.Answer,
    B.QuestionID,
    B.Question
FROM TblAnswers A INNER JOIN TblQuestion B
    ON A.QuestionID=B.QuestionID
Select Distinct ta.*, tq.* 
from TblAnswers ta,TblQuestions tq 
where ta.QuestionId=tq.QuestionId

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM