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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:28:07+00:00 2026-05-23T09:28:07+00:00

Ive got a problem where I want to delete orphaned records. I was wondering

  • 0

Ive got a problem where I want to delete orphaned records. I was wondering what the syntax is for deleting records that aren’t in a join.

So if my query to get the stuff (that I dont want to delete is):

select * from tbl_user tu
inner join tbl_user_group_xref tugx on tu.userid=tugx.userid

Then how do I
1) get the stuff that isnt in the clause and 2) delete it?

Like to do it without using arrays but an array solution would still be useful for learning purposes.

  • 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-23T09:28:07+00:00Added an answer on May 23, 2026 at 9:28 am

    There’s an optimization to Duncan Howe’s answer that I know works in MySQL and may work with other servers. It probably also works for t-clausen.dk’s answer in MySQL.

    If you are deleting rows from table t1 that don’t have corresponding rows in t2 and both tables are very large then the server can end up getting swamped with disk seeks. I found that performance can be improved a lot if you can force the server to load t2’s index into memory before running the query and then, in the query, force the server to ignore t1’s index. That makes the server do a sequential scan of t1, which will be an efficient use of disk. The server steps through each row of t1 looking up t2’s index, which is in memory, to determine if the row should be deleted. The disk seeks are thus eliminated and disk IO rate is very high, which keeps the CPU busy.

    For example:

    delete tbl_user 
      from tbl_user tu ignore key (primary)
      left join tbl_user_group_xref tugx 
        use key (userid) on tu.userid=tugx.userid
    where tugx.userid is null
    

    (I’m assuming that tbl_user.userid is its table’s PK and the index on tbl_user_group_xref.userid is named userid. If not, change the respective key names.)

    Forcing a server to load an index into memory is technology-specific. In MySQL for MyISAM tables you can use load index into cache. Recreating an index from scratch (which is very fast in MySQL) might leave it in cache (and would have the nice side effect of balancing the B-tree).

    I’ve seen examples with well over 100x improvement using this optimization. So long as you can cache t2’s index, you can process very large tables efficiently.

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

Sidebar

Related Questions

I've got some tabs. http://img196.imageshack.us/img196/7167/tabs.gif And I want to add a rollover effect. Problem
I've got a problem here with an MSI deployment that I'm working on (using
I've got a problem with inheritance and generics. This is the code that illustrates
I've got a problem similar to,but subtly different from, that described here (Loading assemblies
I've got an interesting problem that's cropped up in a sort of pass based
Ive got a problem. In each document I've got fields: threads.id and posts.id. I
So, basically, I've got a load of code that I want to add to
ive got no problem with inserting the transaction after puchased is completed. the problem
I've got a problem with a singleton implementation. It seems an objet I want
I've got a problem with Symfony2.0 BETA3 and MongoDB. I want create a Document,

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.