简体   繁体   中英

MySQL compare value of field in one table with value of row in a different table

I'm new to SQL and very confused on how to achieve the following:

Update TableA.row1.result with "equal", if TableA.row1.fieldA is equal to the value in TableB.fieldA.columnZ (notice in TableB, the row is named "fieldA", which has the same name given to the column in TableA).

I have this so far, but I'm not sure how to incorporate the update.

SELECT TableA.rowname from TableA 
      INNER JOIN TableB on TableA.fieldA=TableB.fieldID

You should read about multi-table updates ( link to mySQL official documentation )

Try to use this template for your queries.

update TableA, TableB
set TableA.row1_result = TableB.fieldA_columnZ
where TableA.fieldA=TableB.fieldID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM