Pawan
Pawan

Reputation: 32321

First Select If exists then delete under one Query

I have a Table by name Persons

My requirement is that , i need to check if there exists any records inside Persons table with PersonID = 1 and so if exists delete it

I have tried as

DELETE FROM Persons
WHERE PersonID = 1
  AND EXISTS(SELECT PersonID FROM Persons WHERE PersonID = 1 LIMIT 1)

I am getting the following error

1093 - You can't specify target table 'story_category' for update in FROM clause

http://sqlfiddle.com/#!9/ab2b51

could you please tell me how to fix this

Upvotes: 0

Views: 28

Answers (1)

kui.z
kui.z

Reputation: 74

There is no need for such trouble, just do "DELETE FROM Persons WHERE PersonID = 1"

Upvotes: 1

Related Questions