我有一个包含100,000行的表,并希望删除所有重复项。我已经尝试过以下查询:
DELETE t1 FROM wt_tweets t1, wt_tweets t2 WHERE t1.ID < t2.ID AND t1.tweet_id = t2.tweet_id OR t1.tweet_user_id = t2.tweet_user_id
不幸的是,它很慢。所以我想知道是否有更快的替代方案。
答案 0 :(得分:2)
您的查询解析如下:
var path = "c:\\Temp\\HC1.jpg";
byte [] buffer = null;
// image file to binary data
if (System.IO.File.Exists (path)) {
using (var stream = System.IO.File.Open (path, System.IO.FileMode.Open)) {
var len = stream.Length;
buffer = new byte [len];
stream.Read (buffer, 0, (int) len);
stream.Close ();
}
}
// binary data to image file
System.IO.File.WriteAllBytes ("c:\\Temp\\HC11.jpg", buffer);
在这种情况下,这将删除所有行(假设DELETE t1 FROM wt_tweets t1, wt_tweets t2
WHERE (t1.ID < t2.ID AND t1.tweet_id = t2.tweet_id) OR
(t1.tweet_user_id = t2.tweet_user_id)
不是tweet_user_id
)。所以,更快的方法是:
null
但是,我怀疑这是你的意图。
如果你想删除TRUNCATE TABLE wt_tweets;
相同的行(但保留id最大的行):
tweet_id