3

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

1 Answer 1

7

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;
Sign up to request clarification or add additional context in comments.

2 Comments

You're right about the usage of SET but I don't think SQLite supports multi-table UPDATE syntax. You're showing MySQL syntax.
It does support it. That was not the problem. It's been a while since I last used SQL and while looking at the syntax on SQLite documentation (sqlite.org/lang_update.html) was completely missing the fact SET was not part of the field=value cycle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.