【问题标题】:update table based on another tables value in sqLite根据 sqLite 中的另一个表值更新表
【发布时间】:2015-05-23 08:21:04
【问题描述】:

我们有两个表 table1 table2

In table1

Itemnumber    SalesCode
123            213UB
142            132NB
1458           256GD

In table2
Itemnumber    ProductGroupCode
123            
142           
1458  

更新table2后我们需要这样

 Itemnumber    ProductGroupCode
    123            213UB
    142            132NB
    1458           256GD

我们试过这样

tx.executeSql('UPDATE  table2 JOIN  table1 ON (table2.ItemNumber=table1.ItemNumber) SET table2.CustomerPriceGroup = table1.SalesCode');

但是我们遇到了这样的错误

Colud not prepare Statement (Near "JOIN ":syntax error)

请告诉我我的代码有什么问题

【问题讨论】:

    标签: join sqlite sql-update


    【解决方案1】:

    SQLite 不支持在 UPDATE 语句中使用 JOINs

    您可以使用如下子查询获得相同的结果

    UPDATE table2 
    SET table2.CustomerPriceGroup = 
    (SELECT table1.SalesCode FROM table1 WHERE table2.ItemNumber=table1.ItemNumber)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-27
      • 2012-09-05
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多