diff --git a/QueryBuilder/Compilers/Compiler.cs b/QueryBuilder/Compilers/Compiler.cs index aa15c789..ba501d1e 100644 --- a/QueryBuilder/Compilers/Compiler.cs +++ b/QueryBuilder/Compilers/Compiler.cs @@ -346,6 +346,7 @@ protected virtual SqlResult CompileUpdateQuery(Query query) var clause = ctx.Query.GetOneComponent("update", EngineCode); string wheres; + string joins; if (clause != null && clause is IncrementClause increment) { @@ -354,13 +355,14 @@ protected virtual SqlResult CompileUpdateQuery(Query query) var sign = increment.Value >= 0 ? "+" : "-"; wheres = CompileWheres(ctx); + joins = CompileJoins(ctx); if (!string.IsNullOrEmpty(wheres)) { wheres = " " + wheres; } - ctx.RawSql = $"UPDATE {table} SET {column} = {column} {sign} {value}{wheres}"; + ctx.RawSql = $"UPDATE {table} SET {column} = {column} {sign} {value} FROM {table}{joins}{wheres}"; return ctx; } @@ -377,13 +379,14 @@ protected virtual SqlResult CompileUpdateQuery(Query query) var sets = string.Join(", ", parts); wheres = CompileWheres(ctx); + joins = CompileJoins(ctx); if (!string.IsNullOrEmpty(wheres)) { wheres = " " + wheres; } - ctx.RawSql = $"UPDATE {table} SET {sets}{wheres}"; + ctx.RawSql = $"UPDATE {table} SET {sets} FROM {table}{joins}{wheres}"; return ctx; }