I have two database tables:
Definitions table has the following columns:
Id, Category
Sample data:
1, What is capital of USA ?
2, Who broke my glass ?
Options table has the following columns:
Id, DefinitionId, Value
Sample Data:
1, 1, New York
2, 1, Melbourne
3, 1, Lahore
4, 2, Boss
5, 2, My brother
6, 2, Your girlfriend
Please guide me how I can query ALL questions with All options, I need data like below:
"", 1, What is capital of USA ?
1,1, New York
2,1, Melbourne
3, 1, Lahore
"", 2,Who broke my glass ?
4, 2, Boss
5, 2, My brother
6, 2, Your girlfriend
Please guide
For this, use
UNION ALLlike so:Note that: it is better to
JOINthe two tables like so:And don’t consider to do this formatting in SQL;
Update: To get all questions, try this:
SQL Fiddle Demo
This will give you: