I have a query:
select rc.cargo_type_list_code,
xml = (select max(rc2.name) as 'cc' from cargo rc2 where rc2.cargo_type_list_code = rc.cargo_type_list_code for xml)
from cargo rc
group by rc.cargo_type_list_code
When I try to execute it, I get following error:
Received error 107 : The column prefix 'rc' does not match with a table name or alias name used in the query. Either the table is not specified in the FROM clause or it has a correlation name which must be used instead.
When I remove "when" clause I get data with wrong xml. If I remove "for xml" I get data without xml. Is there any way to get correct data with correct xml?