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

  • Home
  • SEARCH
  • 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 782597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:24:38+00:00 2026-05-14T20:24:38+00:00

I am writing a small script to synchronize 2 MySQL tables ( t1 to

  • 0

I am writing a small script to synchronize 2 MySQL tables ( t1 to be ‘mirrored’ to t2 )

In a step I would like to delete rows inside t2 that has been delete in t1 with the same id.

I tried this query :

delete from t2 where t2.id in 
    ( select t2.id left join t1 on (t1.id=t2.id) where t1.id is null )

But Mysql forbid me to use t2 in the same time in the delete and in the select (sound logical by the way)

Of course, I can split the query into 2 queries : first select IDs, then delete rows with these IDs.

My question : do you have a cleaner way to delete row from t2 that does not exist anymore in t1 ? with one query only ?

  • 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-14T20:24:39+00:00Added an answer on May 14, 2026 at 8:24 pm

    This query joins up the two tables and only selects those that don’t have a partner in the new table, thus allowing you to delete them in one go:

    DELETE t2 FROM t2
    LEFT JOIN t1
    ON t2.id = t1.id
    WHERE t1.id IS NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small shell script that needs to reverse the lines of a
I'm writing a small application in VB.NET and I would like some of the
I am writing a small Ruby script that will run in a CLI. To
I'm writing a small agent in java that will play a game against other
I'm writing a small GUI app that contains some editor functionality, and something that
I just finished writing a small script to combine a lot of png pictures
i'm writing a small script to tweet messages from the monitoring systems. The only
I am writing a small script to upload and detect MIME type, using Zend
I am writing a small windows script in javascript/jscript for finding a match for
I am currently writing a small calendar in ASP.Net C#. Currently to produce the

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.