Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:35:39+00:00 2026-05-14T15:35:39+00:00

is there an equivalent of oracle’s rowid in mysql? delete from my_table where rowid

  • 0

is there an equivalent of oracle’s rowid in mysql?

delete from my_table where rowid not in (select max(rowid) from my_table group by field1,field2)

I want to make a mysql equivalent of this query!!!

What i’m trying to do is, : The my_table has no primary key.. i’m trying to delete the duplicate values and impose a primary key (composite of field1, field2)..!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:35:39+00:00Added an answer on May 14, 2026 at 3:35 pm

    In MySql you usually use session variables to achive the functionality:

    SELECT @rowid:=@rowid+1 as rowid
    FROM table1, (SELECT @rowid:=0) as init
    ORDER BY sorter_field
    

    But you can not make sorts on the table you are trying to delete from in subqueries.

    UPD: that is you will need to create a temp table, insert the ranging subquery to the temp table and delete from the original table by joining with the temporary table (you will need some unique row identifier):

    CREATE TEMPORARY TABLE duplicates ...
    
    INSERT INTO duplicates (rowid, field1, field2, some_row_uid)
    SELECT
      @rowid:=IF(@f1=field1 AND @f2=field2, @rowid+1, 0) as rowid,
      @f1:=field1 as field1,
      @f2:=field2 as field2,
      some_row_uid
    FROM testruns t, (SELECT @rowid:=NULL, @f1:=NULL, @f2:=NULL) as init
    ORDER BY field1, field2 DESC;
    
    DELETE FROM my_table USING my_table JOIN duplicates
      ON my_table.some_row_uid = duplicates.some_row_uid AND duplicates.rowid > 0
    

    Since that is one time operation, this should not bring too much overhead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there an oracle equivalent of patindex ? from my search, the only function
Is there MySQL equivalent to Oracle's TIMESTAMP WITH TIME ZONE? I need to map
Is there an equivalent to 1/countif in SQL Server? Something like: SELECT ID,1/COUNTIF(ID) FROM
Is there an equivalent of the Oracle NVL function in SAS? For example, if
Are there equivalent to perl -c syntax check for JavaScript from command? Given that
Is there an ANSI SQL equivalent to Oracle's DECODE function? Oracle's decode function is
I want to use an equivalent of Oracle's nvl() function in Ruby. Is there
This query below: Query 1: SELECT * FROM DUAL is equivalent to and produces
Is there an equivalent to the perl fetchrow_array when connecting to Oracle using Python?
Is there an equivalent or alternative to the following? SELECT mix_type || ' ('

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.