Skip to content
Advertisement

SQL – Update table column values using expression based on two tables

Using a Sqlite database, I have a users table and a ranks table with the following columns:

users table: id | rankid | xp

ranks table id | name | xpLowerLevel

My goal is update the rankId field for all user rows based on the xpLowerLevel field from the ranks table. My Sql expression as follows:

Which gives me the following error no such column: users.xp. What am I doing wrong ?

Advertisement

Answer

With FIRST_VALUE() window function:

Or since there is already the condition:

the difference:

is >= 0,
so there is no need for the function ABS():

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement