I have a query in Mysql and I’m here to seek your inputs.
I have 2 tables T1 and T2 in mysql.
Both contain a common id column with values as shown below –
T1 - 1, 2, 3, 3, 4, 4, 5
and
T2 - 1, 2, 3, 4, 4, 5
I am trying to query table T1 to give me output in the following manner –
1, 2, 3, 4, 4, 5
If one-one relationship exists between T1 and T2 as in value 1, 2, 5 then it is selected from T1. If many-one relationship exists between T1 and T2 as in value 3 in T1 which has one value in T2 then only one value is selected from T1. many-many as in value 4 in T1 and T2 is selected as it is from T1.
It collapses the results from T1 into a distinct set, then re-inflates it based on matches found in T2.