mysql - Delete from subquery -
i using hibernate in application. trying execute following query:
delete activetimes a.begin>=:from , a.begin<=:to , a.end>=:from , a.end<=:to , in( select al activetimes al join al.source.stage st join st.level.datasource ds ds=:datasource)
but error: column 'id' in field list ambiguous
. feels normal, because created sql query looks this:
delete active_times begin>=? , begin<=? , end>=? , end<=? , ( id in ( select id active_times activeti1_ inner join sources sourc2_ on activeti1_.source=sourc2_.id inner join stage stage3_ on sourc2_.id=stage3_.source inner join levels levels4_ on stage3_.level=levels4_.id inner join datasources datasource5_ on levels4_.data_source=datasource5_.id id=? ) )
if change query to:
delete activetimes a.begin>=:from , a.begin<=:to , a.end>=:from , a.end<=:to , a.id in( select al.id activetimes al join al.source.stage st join st.level.datasource ds ds.id=:datasource)
i error: you can't specify target table 'active_times' update in clause
.
i not experimented jpql(or hql) not understand why query looks in first example.
the new error occurs because apparently cannot make subquery on delete table in mysql.
do have suggestions on how can rewrite 1 of above queries in order make work?
just remove sub-query. it's unnecessary. i'm not sure how write sql code in hybernate, i'm guessing this:
delete activetimes join a.source.stage st join st.level.datasource ds a.begin>=:from , a.begin<=:to , a.end>=:from , a.end<=:to , ds.id=:datasource;
Comments
Post a Comment