0

I have tried this query but i am having this error code 1093 this query

delete  
from flow 
where flow.FlowID  in (SELECT flow.FlowID 
                       From flow 
                       WHERE ExpirationDate IS NOT NULL  AND `Username`="XYZ@gmail.com" 
                       GROUP BY Username, FlowName, EffectiveDate 
                       Having COUNT(*) >1 );

1093 error : Can't specify target table in clause.

Rohit Soni
  • 47
  • 1
  • 1
  • 6

1 Answers1

0

Here is my suggestion at a corrected version:

DELETE
FROM flow
WHERE FlowID IN (SELECT FlowID FROM (SELECT FlowID FROM flow
                                     WHERE ExpirationDate IS NOT NULL AND
                                           Username = 'XYZ@gmail.com') t);

The deletion logic here is to delete any record whose FlowID is also associated with a record having a non NULL expiration date and user XYZ@gmail.com. The trick I used to get around the 1093 MySQL error is to wrap the subquery in another subquery. This works by forcing MySQL to materialize that subquery before the update, so it no longer conflicts.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360