简体   繁体   English

如何基于另一个表中的值设置一个表的字段

[英]How to set one table's field based on value in another table

I have two tables. 我有两张桌子。 The first contains a list of ID's. 第一个包含ID列表。 The second has a larger list of ID's. 第二个具有更大的ID列表。 I want to update the second table ONLY if it doesn't exist in the first. 我只想更新第二张表中的第二张表。 This isn't catching all of them: 这并没有抓住所有人:

UPDATE TableB
LEFT OUTER JOIN TableA
ON TableB.id = TableA.id
SET TableB.Status = "Inactive"
WHERE TableB.id IS NULL;

You are close, assuming that TableB is the "second" table: 您很接近,假设TableB是“第二”表:

UPDATE TableB b LEFT OUTER JOIN
       TableA a
       ON b.id = a.id
    SET b.Status = 'Inactive'
WHERE a.id IS NULL;
------^

Your WHERE clause referenced the wrong table. 您的WHERE子句引用了错误的表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL触发错误:根据另一张表的更新或插入更新一个表的字段值 - MySQL Trigger Error: Updating the one table's field value based upon another table updates or insertions 如何基于另一个表中相同值的行为从一个表中选择值? - How to SELECT value from one table based on same value's behavior in another table? 如何基于另一个表的字段查询? - How to query based off another table`s field? 如何使用MySQL根据另一个表的值选择一个值? - How to select a value with MySQL based on another table's value? 如何在一个数据库表中查找其中一个字段的值与另一表中的值不同的行 - How to I find rows in one database table where a value of one field is NOT LIKE a value in another table 如何用一次查询从另一张表的数据更新一张表的所有行字段? - How to updated all row's field of one table from data of another table with one time query? MariaDB:Select 来自基于另一个表字段值的表列 - MariaDB: Select from a table colum based on another table field value MySQL-使用基于另一个表的值填充表字段 - MySQL - populate table field with value based on another table 根据另一个表的字段值从数据库表中查找? - Find from database table based on field value of another table? 如何遍历一个表并根据另一个表中的数据更新字段? - How to loop through one table and update a field based on data in another table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM