Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a column using other column?

Here is my raw SQL:

UPDATE
  "RESULT"
SET
  result_last_clicks = result_clicks;

I can use knex.raw(sql) to do this.

How can I do this by using knex('RESULT').update({result_last_clicks: ??.result_clicks})

update

environments:

"knex": "^0.15.2"

like image 587
slideshowp2 Avatar asked Mar 05 '23 18:03

slideshowp2


1 Answers

This is pretty much of a duplicate of e.g. Knex.js - How To Update a Field With An Expression

Though with latest knex you can use column reference helper instead of knex.raw :

knex('RESULT').update({ 
  result_last_clicks: knex.ref('result_clicks') 
})
like image 68
Mikael Lepistö Avatar answered Mar 19 '23 03:03

Mikael Lepistö