hibernate - SQL select distinct entity - union all - order by another entity's column -
i using sql access entity (forslag), sort using entity's column (b.dato).
this initial sql:
select distinct ff.* forslag ff inner join forlag f on ff.forlag_id = f.forlag_id inner join loggbehandling b on ff.forlag_id = b.forlag_id inner join kontrollpanel p on f.uhrpumote_id = p.saksbehandleruhrpumote_id b.status_id = 7 union select distinct ft.* forslag ft inner join tidsskrift t on ft.tidsskrift_id = t.tidsskrift_id inner join loggbehandling b on ft.tidsskrift_id = b.tidsskrift_id inner join kontrollpanel p on t.uhrpumote_id = p.saksbehandleruhrpumote_id b.status_id = 7 order b.dato desc
hibernate complains: order items must appear in select list if statement contains union, intersect or except operator.
i suspect can't add b.dato
select, assume have impact on mapping:
select distinct ff.*, b.dato forslag ff inner join forlag f on ff.forlag_id = f.forlag_id inner join loggbehandling b on ff.forlag_id = b.forlag_id inner join kontrollpanel p on f.uhrpumote_id = p.saksbehandleruhrpumote_id b.status_id = 7 union select distinct ft.*, b.dato forslag ft inner join tidsskrift t on ft.tidsskrift_id = t.tidsskrift_id inner join loggbehandling b on ft.tidsskrift_id = b.tidsskrift_id inner join kontrollpanel p on t.uhrpumote_id = p.saksbehandleruhrpumote_id b.status_id = 7 order b.dato desc
how should solve this?
are sure hql , not sql???
the first: in hql not possible using union must execute 2 distinct queries.
the second: in sql when use order when have union operation, must apply order result table in way:
the third: why use distinct if use union all?? use union without same thing of distinct.
select * ( select ff.*, b.dato dato forslag ff inner join forlag f on ff.forlag_id = f.forlag_id inner join loggbehandling b on ff.forlag_id = b.forlag_id inner join kontrollpanel p on f.uhrpumote_id = p.saksbehandleruhrpumote_id b.status_id = 7 union select distinct ft.*, b.dato forslag ft inner join tidsskrift t on ft.tidsskrift_id = t.tidsskrift_id inner join loggbehandling b on ft.tidsskrift_id = b.tidsskrift_id inner join kontrollpanel p on t.uhrpumote_id = p.saksbehandleruhrpumote_id b.status_id = 7 ) resulttable order resulttable.dato desc
Comments
Post a Comment