如何删除符合 SQL 中某些条件的一条记录? (内特扎)
我的表中有一些重复的记录,因为事实证明 Netezza 不支持对主键进行约束检查。话虽这么说,我有一些信息完全相同的记录,我只想删除其中一条。我已经尝试过
delete from table_name where test_id=2025 limit 1
这样做,但是
delete from table_name where test_id=2025 rowsetlimit 1
这两种选择都不起作用。我收到一条错误消息“
found 'limit'. Expecting a keyword
是否有任何方法可以限制此查询删除的记录?”我知道我可以删除记录并重新插入它,但这有点乏味,因为我必须多次执行此操作。
请注意,这不是 SQL Server 或 MySQL。这是用于 Netezza
I've got some duplicate records in a table because as it turns out Netezza does not support constraint checks on primary keys. That being said, I have some records where the information is the exact same and I want to delete just ONE of them. I've tried doing
delete from table_name where test_id=2025 limit 1
and also
delete from table_name where test_id=2025 rowsetlimit 1
However neither option works. I get an error saying
found 'limit'. Expecting a keyword
Is there any way to limit the records deleted by this query? I know I could just delete the record and reinsert it but that is a little tedious since I will have to do this multiple times.
Please note that this is not SQL Server or MySQL.This is for Netezza
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果它不支持“DELETE TOP 1”或“LIMIT”关键字,您最终可能必须执行以下操作之一:
1)添加某种自动递增列(如 ID),使每一行独特的。不过,我不知道创建表后是否可以在 Netezza 中执行此操作。
2)使用某种编程语言以编程方式读取整个表,以编程方式消除重复项,然后删除所有行并再次插入它们。如果它们被其他表引用,则这可能是不可能的,在这种情况下,您可能必须暂时删除约束。
我希望这有帮助。请告诉我们。
并供将来参考;这就是为什么我个人总是创建一个自动递增的 ID 字段,即使我认为我永远不会使用它。 :)
If it doesn't support either "DELETE TOP 1" or the "LIMIT" keyword, you may end up having to do one of the following:
1) add some sort of an auto-incrementing column (like IDs), making each row unique. I don't know if you can do that in Netezza after the table has been created, though.
2) Programmatically read the entire table with some programming language, eliminate duplicates programmatically, then deleting all the rows and inserting them again. This might not be possible if they are references by other tables, in which case, you might have to temporarily remove the constraint.
I hope that helps. Please let us know.
And for future reference; this is why I personally always create an auto-incrementing ID field, even if I don't think I'll ever use it. :)
以下查询适用于从表中删除重复项。
The below query works for deleting duplicates from a table.
如果记录相同,那么您可以执行类似的操作
您甚至可以创建一个子查询来选择所有具有 COUNT(*) > 的 test_ids 1 自动查找第 1 步和第 3 步中的受骗者
If the records are identical then you could do something like
You could even create a sub-query to select all the test_ids HAVING COUNT(*) > 1 to automatically find the dupes in steps 1 and 3
GROUP BY 1,2,3,....,n 将消除插入临时表时的重复
The GROUP BY 1,2,3,....,n will eliminate the dupes on the insert to the temp table
Netezza 中是否允许使用 rowid...据我所知,我认为该查询不会在 Netezza 中执行...
Does the use rowid is allowed in Netezza...As far as my knowledge is concern i don't think this query will executed in Netezza...