views:

292

answers:

2

Hello all,

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

+5  A: 

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;
John Kugelman
DOH! Thanks John.
Krugar
You're right about the usage of `SET` but I don't think SQLite supports multi-table `UPDATE` syntax. You're showing MySQL syntax.
Bill Karwin
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 (http://www.sqlite.org/lang_update.html) was completely missing the fact SET was not part of the field=value cycle.
Krugar
A: 

The Sqllite site hosts documentation, including a SQL reference. Find the syntax for UPDATE here.

APC