I have table as follow in my POSTGRES database
Table name:userDetails
column 1: userId (Bigint)
column 2: questionId1 (int) Foreign key:: userQuestions(id)
column 3: answer1 (String)
column 4: questionId2 (int) Foreign key:: userQuestions(id) |
column 5: answer2 (String)
Table name: userQuestions
column 1: id(bigint)
column 2: question(String)
and i want to select output as follow on the basis of userId,
column 1: userId (Bigint)
column 2: questionId's (int [])(questionId1 and questionId2)
column 3: questions (String [])( array of questions from table userQuestions against the the questionId1 and questionId2 )
column 4: answer(String []) (answer1 and answer2 from userDetails table in array of String)
please help me to write sql query.
SAMPLE DATA
Tablename :: userDetails
|userId |questionId1 |answer1 |questionId2 |answer2
abc 1 "hp" 2 "tommy"
Tablename :: userQuestions
id question
1 "What is brand name of your laptop?"
2 "What is name of your pet?"
Expected OUTPUT::
userId questionIds answers questions
abcd [1,2] ["hp","tommy"] ["What is brand
name of your
laptop?",
"What is name of
your pet?"]
UserQuestionsdoesn't seem to have a connection toUsers. I'm expecting a junction table, with one row per user and per question.