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 4103366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:56:57+00:00 2026-05-20T20:56:57+00:00

I have MySQL MyISAM table: Table friends(id, friend_id): 1, 5 5, 1 2, 6

  • 0

I have MySQL MyISAM table:

Table friends(id, friend_id):

1, 5

5, 1

2, 6

6, 2

3, 7

How to delete reverse records? If for record values «1, 5» exist record with values «5, 1» i need to delete «5, 1».

Thanx for help!

  • 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-20T20:56:58+00:00Added an answer on May 20, 2026 at 8:56 pm
    DELETE F1
    FROM friends F1, friends F2
    WHERE F1.friend_id = F2.id
      AND F2.friend_id = F1.id
      AND F1.id > F1.friend_id
    

    EDIT

    A bit nicer syntax would be:

    DELETE F1
    FROM friends F1
      JOIN friends F2 ON F1.friend_id = F2.id AND F2.friend_id = F1.id
    WHERE F1.id > F1.friend_id
    

    But execution time is the same.

    As well, I’ve created this small script for a quick & dirty benchmark.

    Results:

    No index:

    Dalen: 600 => 400 rows. Time: 0.0274
    Mark: 600 => 400 rows. Time: 0.4323
    Frosty: 600 => 400 rows. Time: 0.4081
    Nick: 600 => 400 rows. Time: 0.3201
    

    Separate index on columns id and friend_id:

    Dalen: 600 => 400 rows. Time: 0.0201
    Mark: 600 => 400 rows. Time: 0.0095
    Frosty: 600 => 400 rows. Time: 0.0059
    Nick: 600 => 400 rows. Time: 0.3257
    

    Unique index on (id, friend_id):

    Dalen: 600 => 400 rows. Time: 0.0168
    Mark: 600 => 400 rows. Time: 0.0057
    Frosty: 600 => 400 rows. Time: 0.0041
    Nick: 600 => 400 rows. Time: 0.3209
    

    Conclusions:

    • Dalen: fastest when columns are not indexed
    • Frosty: fastest when columns are indexed (Mark’s being close, even faster in “indexed cases” without considering the tmp table creation time. However, the additional time required by the tmp table creation increases when the fields are indexed)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySql table (MyISAM) with 25.000 records and 1.8 MB size. The
I have a mysql (5.0.22) myisam table with roughly 300k records in it and
In a mysql MyISAM table, I have a column type mediumblob and storing captured
Say you have a MySQL 5.0 MyISAM table with 100 million rows, with one
I have a large mysql MyISAM table with 1.5mil rows and 4.5GB big, still
I have a MySQL MyISAM table with about 400 million rows of price data
I have a mysql MyISAM table with many rows that contain information about places,
I have a MySql MyISAM table with a full text index, like this: CREATE
I have a myISAM table running in production on mySQL, and by doing a
I have a MySQL-table called customers1 running engine MyISAM. I've created a full text

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.