Hi @szymon_dybczak ,
Thanks for your reply. The above code is working fine which means multiple updates can be done from a single source target. So, it may be when there are complex matching conditions/values, merge query gives error.
I cannot send you exact code. However, I tried to mimic the query in case you have any further suggestions. For below query, I am getting merge conflict error as mentioned above.
Here, I am trying to update the target table based on a source table. However, since there were multiple records in source table, I used max and group by to get unique record. I checked using count, we are having distinct record in source table query,S1 after applying max and group by. However, the query is still giving me merge conflict error saying multiple sources. I further researched to find out that sometimes when we have multiple records in target table, then also we get this error. But could not find anything concrete on Databricks website on this. Please suggest.
%sql
merge into target table T
using(select max(col1) as col1,max(col2) as col2 from source table S where col3='A' group by col 4,col 5,col 6)s1)
on upper(trim(T.col4)) = upper(trim(s1.col4)) and upper(T.col5) = upper(S1.col5)
and upper(T.col6) =upper(S1.col6) and T.col3='A'
when matched then update set
T.col1=s1.col1, T.col2=s1.col2
Please Note: The above code is working fine for few cases and giving error for other cases.