laravel-5 - Laravel - 用 table2 列更新 table1 列
问题描述
我想在迁移脚本中使用这种查询。
update table1, table2 set table1.column = table2.another_column where table1.id=table2.foreign_id
如何以 laravel/雄辩的方式做到这一点?
解决方案
试试这个:
DB::table('table1')
->join('table2', 'table1.id', 'table2.foreign_id')
->update(['table1.column' => DB::raw('table2.another_column')]);
推荐阅读
- pine-script - Pine Script 初学者,plotshape
- c# - 通过 ref C# button_on_click
- ajax - RxJS AJAX 检测请求是从 progressSubscriber 完成的(无论是成功还是错误)
- java - 当 PC 进入休眠模式时,Java 如何计算休眠时间?
- ruby-on-rails - Ransack 是否有办法实现令牌搜索
- r - 如何使用汽车包版本 3 在 scatterplot() 中使用图例参数
- php - 如何使用 php 在输入标签中使用条件?
- python - Pandas:将列值与字典键进行比较并更新新列中的值
- python - 为什么空列表在 Python 的 while 循环中计算为 False
- apache-spark - Spark SQL 是否会一直检查所有分区的信息,甚至指定分区?