Update SQLite row with certain number

651 Views Asked by At

I have a problem that I can't solve with better-sqlite3 on node.js I have a table looking somewhat like this:

image of table

How can I change each rows xp, that has a level of 3 to 100? So in this example it should change id's 1 and 4 xp value to 100.

Any help is appreciated!

1

There are 1 best solutions below

0
On

This is a pretty basic SQL Query, you're just needing to do a WHERE on all levels that equal 3.

UPDATE tableName
SET level = 100
WHERE level = 3

Looking at the better-sqlite3 documentation, to do an UPDATE you simply need to call the function using run()

const stmt = db.prepare('UPDATE tableName SET level = ? WHERE level = ?');
const info = stmt.run(3, 100);