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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:53:54+00:00 2026-05-13T10:53:54+00:00

Given two tables A and B in a MySQL Database, how can one update

  • 0

Given two tables A and B in a MySQL Database, how can one update a field in a row of table A if and only if certain fields in the fore-mentioned row in table A exactly match fields in a distinct row of table B. The rows in table B must be used once and only once for each comparison. As such, a row in Table B that has fields matching a row in Table A can not be used a gain to match any other row in Table A.

I have tried

UPDATE
    Table A,
    Table B
SET 
    Table A.Status = 'MATCHED',
        Table B.Status = 'USED'
WHERE
    Table B.Status IS NULL
AND 
    Table A.Field1 = Table B.Field1
AND 
    Table A.Field2 = Table B.Field2

Unfortunately, this does not give my desired results since different rows from Table A tend to get matched with the same row in Table B.

For example: Table A

ID  Date       Ref    Amount  Status 
1   2009-10-20 773    300000         
2   2009-10-20 773    10000   MATCHED
3   2009-10-20 773    150000         
4   2009-10-20 773    20000   MATCHED
5   2009-10-20 773    140000  MATCHED

Table B

 Ref Amount Date       ID
 870 50000  2009-11-01 1 
 871 50000  2009-11-01 2 
 871 80000  2009-11-01 3 
 871 20000  2009-11-01 4 
 871 20000  2009-11-01 5 
 871 20000  2009-11-01 6 
 872 300000 2009-11-01 7 

To match using Ref, Amount and Date.

  • 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-13T10:53:55+00:00Added an answer on May 13, 2026 at 10:53 am

    Could it be as simple as adding exclusions to the WHERE clause to avoid reuse?

    AND Table A.Status <> 'MATCHED'
    AND Table B.Status <> 'USED'
    

    This will work if each row is updated in turn, but not if it’s set based and transactional. My apologies for not testing this; I don’t have MySQL here to try this with.

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why not use mysql_insert_id() ? As for your question if… May 16, 2026 at 4:14 pm
  • Editorial Team
    Editorial Team added an answer Are you sure you're using suExec PHP? If it's just… May 16, 2026 at 4:13 pm
  • Editorial Team
    Editorial Team added an answer From the developer page: "Returns the X coordinate of this… May 16, 2026 at 4:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am creating an update form where previously submitted information from a mysql database
I need to query the database by joining two tables. Here is what I
I have two database tables with the following structure: actions: action_id int(11) primary key
I've constructed a database in MySQL and I am attempting to map it out
I have 2 files, one is used to view the data in the mysql
I have two tables, rating: +-----------+-----------+-------------+----------+ | rating_id | entity_id | rating_code | position
I have a table in database that is having unique id's. I have a
I've got a database with three tables: Books (with book details, PK is CopyID),
I'm working on building a MySQL database and I'm thinking that rather than encode
I'm trying to determine the best general approach for querying against joined two tables

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.