Equivalent of Oracle’s RowID in MySQL -
is there equivalent of oracle's rowid in mysql?
delete my_table rowid not in (select max(rowid) my_table group field1,field2)
i want make mysql equivalent of query!!!
what i'm trying is, : my_table has no primary key.. i'm trying delete duplicate values , impose primary key (composite of field1, field2)..!!
in mysql use session variables achive functionality:
select @rowid:=@rowid+1 rowid table1, (select @rowid:=0) init order sorter_field
but can not make sorts on table trying delete in subqueries.
upd: need create temp table, insert ranging subquery temp table , delete original table joining temporary table (you need unique row identifier):
create temporary table duplicates ... insert duplicates (rowid, field1, field2, some_row_uid) select @rowid:=if(@f1=field1 , @f2=field2, @rowid+1, 0) rowid, @f1:=field1 field1, @f2:=field2 field2, some_row_uid testruns t, (select @rowid:=null, @f1:=null, @f2:=null) init order field1, field2 desc; delete my_table using my_table join duplicates on my_table.some_row_uid = duplicates.some_row_uid , duplicates.rowid > 0
since 1 time operation, should not bring overhead.
Comments
Post a Comment