Update only in case where its not null
本问题已经有最佳答案,请猛点这里访问。
我希望用select from table2从表1中更新列(A),但仅当表2中现有列(B)不为空时才进行更新。我不想使用WHERE语句(不为空),因为它会影响我的所有代码。
我的代码示例:
1 | UPDATE table1 SET COLUMN(a) = (SELECT COLUMN(b) FROM table2) |
我在试这样的东西
1 | UPDATE table1 SET COLUMN(a) = NOT NULL(SELECT COLUMN(b) FROM table2) |
号
例子:
1 | UPDATE ExpressMarketCheck SET Barcode = (SELECT barcode FROM ExpressMarket), Name=(SELECT name FROM expressmarket), price=(SELECT price FROM expressmarket) |
我想你想要一个
1 2 3 4 5 6 7 | UPDATE emc SET Barcode = em.barcode, Name = em.name, price= em.price FROM ExpressMarketCheck emc JOIN expressmarket em ON emc.?? = em.??; |
我不能从你的问题中分辨出应该为
MySQL有一个
1 2 3 4 | UPDATE your_table_name SET your_column_name="data", scan_created_date = ISNULL( your_column_name,"data" ) WHERE id = X |
号
可以使用此查询来实现约束。
1 | UPDATE ExpressMarketCheck SET Barcode = (SELECT barcode FROM ExpressMarket WHERE barcode IS NOT NULL) |