I am building a reporting database and part of the requirements is creating multiple boolean columns to flatten 1:M relationships. Here’s an example:
Table 1 is Study Table and has a unique id.
Table 2 is Languages Table and has a 1:many relationship with Table 1.
Study Table
Id Name
1 Study1
2 Study2
3 Study3
LanguageTable
StudyId Language
1 English
1 French
1 Chinese
2 French
3 Chinese
I want to have a few columns in my report table such as Is In English or Is in European Language i.e
Study Language Report
StudyId IsInEnglish IsInEuropeanLanguage
1 true true
2 false true
3 false false
How would I build a SQL query to generate this table given Table 1 and Table2?
1 Answer