I am not a expert query writer . Scratching my head over this one . Can anyone help me out for this ?
Table tbF
RecordId MarketId
101 1
102 1
201 2
301 3
Table tbSB
MarketId BMId
1 3
1 5
2 1
2 2
2 3
2 4
2 5
3 1
Table tbFM
RecordId BMId
101 3
102 3
102 5
201 1
201 3
201 4
Now I want a output as
Record Id MarketId BMId Active
101 1 3 true
101 1 5 false
102 1 3 true
102 1 5 true
201 2 1 true
201 2 2 false
201 2 3 true
201 2 4 true
201 2 5 false
301 3 1 false
Active column –>
If the record id present is mapped to the particular BMId its true else false
RecordId belongs to a market . –> Table tbF
Each Market has certain no of BMId mapped for it –>tbSB
Each Recordid has certain no of BMId mapped for it –>tbFM
for each record if the BMid is present in tbFM then active is true
else if the BMId is mapped for records market and not for record then for that record Active is false
I’ve taken Active to be determined by the existance within the tbFM table – since the expected output shown in the question matches that logic.