使用Minus插入mysql时出现语法错误

时间:2017-03-21 14:25:11

标签: mysql sql-insert bigdata

我在mysql插入命令中有语法错误,你有什么建议吗? 提前谢谢

    insert = "INSERT INTO dbpedia_untyped_instance SELECT resource FROM stat_resource MINUS (SELECT resource FROM dbpedia_types UNION SELECT resource FROM dbpedia_disambiguations)";
    try {
        stmt.execute(insert);
    } catch (SQLException e) {
        System.out.println("Error inserting into untyped instance table");
        e.printStackTrace();
    }

1 个答案:

答案 0 :(得分:0)

MySQL目前不支持MINUS

作为解决方法,您可以使用排除联接。

这样的事情对你有用(另一种选择是使用NOT EXISTS):

SELECT RESOURCE
FROM stat_resource
LEFT OUTER JOIN dbpedia_types 
  ON dbpedia_types.resource = stat_resource.resource
LEFT OUTER JOIN dbpedia_disambiguations 
  ON dbpedia_disambiguations.resource = stat_resource.resource
WHERE dbpedia_types.resource IS NULL
  AND dbpedia_disambiguations.resource IS NULL