mysql - Write delete query using GROUP BY, HAVING -


i have mysql query group by, having.

query working fine need delete same records, , when trying delete these record getting error.

select query

select * user_location_history (timestampdiff(day,from_unixtime(location_date/1000),sysdate())>30) , user_id in (select user_id user_location_history (timestampdiff(day,from_unixtime(location_date/1000),sysdate()) < 30) group user_id having count(1) > 100) order id asc limit 200 

delete query

delete user_location_history (timestampdiff(day,from_unixtime(location_date/1000),sysdate())>30) , user_id in (select user_id user_location_history (timestampdiff(day,from_unixtime(location_date/1000),sysdate()) < 30) group user_id having count(1) > 100) order id asc limit 200 

error

error code: 1093 can't specify target table 'user_location_history' update in clause

one way around problem wrap subquery in subquery:

delete user_location_history  timestampdiff(day,from_unixtime(location_date/1000),sysdate())>30        ,         user_id in (           select user_id            (select user_id                  user_location_history                  timestampdiff(day,                                     from_unixtime(location_date/1000),                                     sysdate()) < 30                 group user_id                  having count(1) > 100) t) order id asc limit 200 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -