I am trying the below query in spring boot jpa : version=2.4.5
when I see the show SQL for this query, it is doing select p.name instead of case selection
select CASE WHEN (p.name is null) THEN pi.name ELSE p.name END from Product p left join ProductInfo pi ON p.productInfoId=pi.id
CodePudding user response:
I think your select query is hard to read. So use coalesce instead of case when keyword.
Like:
select coalesce(p.name, pi.name) as productName from Product p left join ProductInfo pi ON p.productInfoId=pi.id