Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
learner321
Starting Member
2 Posts |
Posted - 2012-08-10 : 06:36:58
|
| Hi friends I have one table having quiz, another having questions of quiz, radio button third having options for every quiz question and fourth having checkbox items as option for question in quiz. A question can have either radio button (single option) choice or checkbox option choice. I have joined it but it giving result for either radioboxes or checkboxes. If I join for radioboxed then questions which are having option for that are only displaying, if I select question having checkbox as option is shwoing only questins having checkbox as option. I want to select all questions if it has either radio button options or checkbox option. Please help. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-08-10 : 06:48:37
|
Please send your current DML (table sctructure), and some proper sample data for us to play with.Remember, you cannot access your local server! N 56°04'39.26"E 12°55'05.63" |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-10 : 06:48:37
|
If you can post the queries that you have currently that would make it easier for someone to respond more appropriately. My guess would be that you need left joins, something like this:SELECT q.QuestionId, CASE WHEN q.QuestionType = 'SingleOption' THEN r.Answer ELSE m.Answer END AS AnswerFROM Questions q LEFT JOIN RadioButtonChoices r ON q.QuestionId = r.QuestionId LEFT JOIN MultipleChoices m ON q.QuestionId = m.QuestionId; |
 |
|
|
learner321
Starting Member
2 Posts |
Posted - 2012-08-10 : 07:29:30
|
| Both of you thanks for the answer. The structure and sample data is like this:Table 1 Questions:uid,questionTable 2 Single option:uid, option1, quistioniduid, option2, questionidTable 3 Multiple Option:uid, option1, quistioniduid, option2, questionidExample:Question 1: Which SQL server do you like most (having only radio buttons): o MSSQL o MySQL o PostgresQuestion 2: Which languge do you use to program (having checkboxes): - C# - java - phpI want to retrieve record like this, first line is headerQuestion Radio Button Column Checkbox Columnquestion 1 MSSQL NULLquestion 1 MySQL NULLquestion 1 Postgres NULLquestion 2 NULL C#question 2 NULL Javaquestion 2 NULL Php |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-08-10 : 07:52:22
|
Why are the single option and multioption answers separated into two tables? N 56°04'39.26"E 12°55'05.63" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-08-10 : 07:56:26
|
[code]SELECT t1.Question, t2.[Option] AS RadioAnswer, t3.[Option] AS CheckAnswerFROM dbo.Table1 AS t1LEFT JOIN dbo.Table2 AS t2 ON t2.QuestionID = t1.QuestionIDLEFT JOIN dbo.Table3 AS t3 ON t3.QuestionID = t1.QuestionIDORDER BY t1.uID, COALESCE(t2.uID, t3.uID);[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|
|
|