转载:http://stackoverflow.com/questions/3845718/sql-how-to-update-table-values-from-another-table-with-the-same-user-name

文章内容如下所示:

sql: how to update table values from another table with the same user name?

question:

    I have two tables, with a same column named user_name, saying table_a, table_b. I want to, copy from table_b, column_b_1, column_b2, to table_b1, column_a_1, column_a_2, respectively, where the user_name is the same, how to do it in sql statement?

answer:

    As long as you have suitable indexes in place this should work alright:

UPDATE table_aSET      table_a.column_a_1 = (SELECT table_b.column_b_1                             FROM table_b                            WHERE table_b.user_name = table_a.user_name )    , table_a.column_a_2 = (SELECT table_b.column_b_2                            FROM table_b                            WHERE table_b.user_name = table_a.user_name )WHERE    EXISTS (        SELECT *        FROM table_b        WHERE table_b.user_name = table_a.user_name    )

    UPDATE insqlite3does not support a FROM clause, which makes this a little more work than in other RDBMS.

    If performance is not satisfactory, another option might be to build up new rows for table_a using a select and join with table_a into a temporary table. Then delete the data from table_a and repopulate from the temporary.

结果:经测试该方法可行。靠谱!赞一个!哈哈!

更多相关文章

  1. js简单判断移动端系统的方法
  2. Android中Service(服务)和Thread(线程)的关系
  3. Android(安卓)取消GridView和ListView item被点击时的效果
  4. 关于Handler.removemessages方法
  5. SystemUI之——信号显示流程,基于Android(安卓)P AOSP
  6. Android(安卓)解决WebView调用loadData()方法显示乱码的问题
  7. android支付宝问题2013-07-17
  8. Android(安卓)之 对话框总结

随机推荐

  1. Android编译时报错:Error:Connection time
  2. Android(安卓)Studio 可视化界面 (Design)
  3. android 上傳圖片的幾種方法
  4. Android(安卓)Studio基本常用快捷键
  5. 揭秘uc浏览器三
  6. Android(安卓)测试工具,实时抓被测app cra
  7. Android(安卓)RectF()用法
  8. 说说Android的广播(5) - 广播的历史
  9. eclipse工程转入android studio后碰见的
  10. 由packagename得到应用程序信息