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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:35:33+00:00 2026-05-27T10:35:33+00:00

I have 5 tables. how to update one data that check if this data

  • 0

I have 5 tables. how to update one data that check if this data has not already exist in all the 5 tables.

I know something like INSERT ... ON DUPLICATE KEY UPDATE, but not find an example for multi-tables.

Now I use some poor query like:

mysql_query("UPDATE table1 SET image = '' WHERE image = '".$image."' ");
mysql_query("UPDATE table2 SET image = '' WHERE image = '".$image."' ");
mysql_query("UPDATE table3 SET image = '' WHERE image = '".$image."' ");
mysql_query("UPDATE table4 SET image = '' WHERE image = '".$image."' ");
mysql_query("UPDATE table5 SET image = '' WHERE image = '".$image."' ");
mysql_query("UPDATE table1 SET image = '".$image."' WHERE id = '".$id."'");

First update empty value for each table where the data is DUPLICATE then insert the value. this will cost more mysql connects I think… So how to use less query do this update? Thanks.

EDIT1: tried something below, it will update the value ignore to check if the value has already exited in one table of the five.

mysql_query("
UPDATE table1,table2,table3,table4,table5 
SET table1.image='".$image."' 
WHERE table1.id='".$id."' 
AND table1.image!='".$image."' 
AND table2.image!='".$image."' 
AND table3.image!='".$image."' 
AND table4.image!='".$image."' 
AND table5.image!='".$image."'
");
  • 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-27T10:35:33+00:00Added an answer on May 27, 2026 at 10:35 am

    ok, i think this is what you asked for

    update table1 AS t1
             LEFT JOIN table1 AS t1copy
               ON t1copy.image = '$image'       
       set t1.image = '$image'
     where t1.id = $id
       and t1copy.image IS NULL
       and not exists(select 1 from table2 where table2.image = '$image' )
       and not exists(select 1 from table3 where table3.image = '$image' )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have MySQL query like this one: UPDATE table_name SET 1 =
I have two tables, and want to update fields in T1 for all rows
I have a couple of tables (mySQL) that i would like to update with
I have a data transfer tool that transfers information from one database to another.
I have two tables that get joined regularly. Table One is about 1 Million
I have a web page that shows a table of data. My page has
I have this SQL update query: UPDATE table1 SET table1.field1 = 1 WHERE table1.id
In MySQL I have to check whether select query has returned any records, if
NOTE: This is the simple version of my previous question that SHOULD have been
We have a web application that manages inventory for our computer support group. One

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.