如何从同一个表中的select中删除MySQL

时间:2012-07-17 22:14:56

标签: mysql sql

您好我有一个相当复杂的查询,我在SQLite中已经使用了很长时间。它是这样开始的:

delete FROM 
   verbal_sets 
WHERE verbal_sets.verbal_set_id IN( 
   SELECT 
       F.verbal_set_id 
   FROM verbal_sets AS F WHERE Exists( 
       SELECT 
         knowledge_id, phrase_id,first_entity_text, second_entity_text,verbal_relation_text, Count(verbal_set_id) 
       FROM
        (...)

我现在正在创建相同软件的MySQL支持版本,但MySQl不喜欢这个查询。它返回错误:

[Err] 1093 - You can't specify target table 'verbal_sets' for update in FROM clause

我没有MySQL细节的经验。任何人都可以指出我必须对此查询做些什么?

2 个答案:

答案 0 :(得分:0)

我希望这会对你有所帮助,

delete FROM 
   verbal_sets 
WHERE verbal_set_id IN( 
   SELECT * 
    From( 
       SELECT knowledge_id, 
              phrase_id,
              first_entity_text, 
              second_entity_text, 
              verbal_relation_text, 
              Count(verbal_set_id) 
       FROM  verbal_sets
       ) as c
)

答案 1 :(得分:-1)

请跳过几行:

DELETE FROM 
   verbal_sets 
WHERE Exists( 
       SELECT 
         knowledge_id, phrase_id,first_entity_text, second_entity_text,verbal_relation_text, Count(verbal_set_id) 
       FROM