Skip to content
Advertisement

How to execute multiple joins with different params in a single query

I have two tables, question(question_id) and question_exclusion(question_type, question_sub_type, question_id)

I’m able to do it If I specify question_type and question_sub_type.

But what I want to achieve is to get all questions with questions_ids in a single query for all possible question_type and questions_sub_type

question_type and questions_sub_type are dynamic parameters I don’t know exact values until query execution

Update 1:

actual data:

table: question

table: question_exclusion

expected result:

its like a list of lists for each type and sub_type combination taking into consideration exclusion table

For example:

Of course I can query all distinct (type, sub_type) and make another query by combining with union

I’m looking for another solid way of doing this in a single query

Advertisement

Answer

I add row (A | A_1 | 10) into question_exclusion in your data for more clean solution:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement