SQL wizards: I have a query which needs to be written as with left joins so it will work with TD 12 (scalar subqueries do not work). Here it is: Thank you in advance for looking and hopefully soliving. Currently the following yields: SELECT Failed. 3706: Syntax error: expected something between '(' and the 'SELECT' keyword. No explain available.
select
id,
(select
case
when Category_1 = b.MaxScore then 'Category_1'
when Category_2 = b.MaxScore then 'Category_2'
when Category_3 = b.MaxScore then 'Category_3'
else 'NA'
end
from myTable t where t.id = b.id
) as MaxScoreCategory,
MaxScore
from (
select
id,
max(Score) as MaxScore
from (
select id, 'Category_1', Category_1 from myTable union all
select id, 'Category_2', Category_2 from myTable union all
select id, 'Category_3', Category_3 from myTable
) a(id, Category, Score)
group by id
) b