Mis*_*ich 3 php mysql inner-join laravel
我需要表目录中的更新键,并编写查询(mysql查询正确):
```
update attributes a inner join catalog c on a.parent_id = c.id set a.key = c.left_key
```
and with Laravel DB:
```
DB::table('attributes as a')
->join(catalog as c', 'a.parent_id', '=', 'c.id')
->update([ 'a.key' => 'c.left_key' ]);
```
It's right query, but DB::table ... make all key in table catalog to 0.
I write
```
DB::statement('update attributes a inner join catalog c on a.parent_id = c.id set a.key = c.left_key;');
```
Run Code Online (Sandbox Code Playgroud)
它的工作!但我不明白为什么带有连接和更新的DB :: table无法正常工作
您可以尝试:
DB::table('attributes as a')
->join('catalog as c', 'a.parent_id', '=', 'c.id')
->update([ 'a.key' => DB::raw("`c`.`left_key`") ]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5875 次 |
| 最近记录: |