1

There are same url in my table. Each row can be identified by id. I want to delete same data in url fields. I am using mysql. I am trying select one(identified by the maximum id) of them as a new tempary table as t2, and then compare url between the original table and the tempary table in my where clause. There is syntax error in my statements, but I am not sure where it is. can u help me? thx guys.

The statements as follow:

delete from t1, 
(select url, max(id) as id
        from tjob_webpage as t1 
        group by url
) as t2 
where t1.url = t2.url 
      t1.id < t2.id;
4

1 回答 1

2

尝试这个,

delete t1
from t1 INNER JOIN
(select url, max(id)  maxID
        from tjob_webpage
        group by url
) as t2 
where t1.url = t2.url 
      t1.id < t2.maxID;
于 2012-08-29T09:03:48.773 回答