sql - Database lookup for each value of another database lookup -


i not sure how word have started sql , have finished going on simple joins.

ill start tables first:

tblquestions

 | survey id | user id | entry date | question 1 | question 2 | question 3 | question 4 | |     1     |   305   |    date    |      0     |      1     |     2      |      3     |  

tblvalues

 |  vid  | textvalue | |   0   |   never   | |   1   |    | |   2   | | |   3   |     | 

i want sql query outputs textvalues of each questions vid. can't store text values directly because data exported charts. understand repetitive data bad table design , rule when normalize tables.

is possible through single query?

edit: using ms access. desired output:

 | survey id | user id | entry date | question 1 | question 2 | question 3 | question 4 | |     1     |   305   |    date    |    never   |     |  |      |  

you want join 1 survey record 4 answer records, must query answer table 4 times. use table aliases in order distinguish 4 records:

select    q.survey_id, q.user_id, q.entry_date,   v1.textvalue, v2.textvalue, v3.textvalue, v4.textvalue tblquestions q join tblvalues v1 on v1.vid = q.question1 join tblvalues v2 on v2.vid = q.question2 join tblvalues v3 on v3.vid = q.question3 join tblvalues v4 on v4.vid = q.question4; 

update: access has additional join requirements, chris has pointed out. above standard sql query has modified thus:

select    q.survey_id, q.user_id, q.entry_date,   v1.textvalue, v2.textvalue, v3.textvalue, v4.textvalue (((tblquestions q inner join tblvalues v1 on v1.vid = q.question1) inner join tblvalues v2 on v2.vid = q.question2) inner join tblvalues v3 on v3.vid = q.question3) inner join tblvalues v4 on v4.vid = q.question4; 

Comments