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
Post a Comment