Sqlite – SQL Syntax error on table update

sql-updatesqlitesyntax-error

Why is that I'm getting a syntax error on the following SQL statement under sqlite?

Error reads:

SQL Error: near "SET": syntax error

UPDATE nova
       SET Nome = (select Nome from assessores where nova.ID = assessores.ID),
       SET Morada = (select Morada from assessores where nova.ID = assessores.ID),
       SET Email = (select Email from assessores where nova.ID = assessores.ID),
       SET TelfCasa = (select TelfCasa from assessores where nova.ID = assessores.ID),
       SET TelfEmprego = (select TelfEmprego from assessores where nova.ID = assessores.ID),
       SET Telemovel = (select Telemovel from assessores where nova.ID = assessores.ID),
       SET Fax = (select Fax from assessores where nova.ID = assessores.ID)
WHERE EXISTS (select * from assessores where nova.ID = assessores.ID);

If I try to fully qualify the SET field names, the error becomes:

SQL Error: near ".": syntax error

Best Solution

You only need one SET at the beginning. You can also simplify the query by joining the two tables together and eliminating the sub-queries.

UPDATE nova JOIN assessores ON nova.ID = assessores.ID
SET nova.Nome        = assessores.Nome,
    nova.Morada      = assessores.Morada,
    nova.Email       = assessores.Email,
    nova.TelfCasa    = assessores.TelfCasa,
    nova.TelfEmprego = assessores.TelfEmprego,
    nova.Telemovel   = assessores.Telemovel,
    nova.Fax         = assessores.Fax;