0

Here is my SQL query:

UPDATE Q
SET Q.FirstName="ram"
FROM Person Q

It gives me the following error:

Error 1: could not prepare statement (1 near ".": syntax error)

Can anyone tell me where I went wrong with this? Thanks in advance.

underscore_d
  • 6,309
  • 3
  • 38
  • 64
AAjit
  • 61
  • 1
  • 10
  • 3
    Should tag your RDBMS, but try `'` instead of `"` – Aaron Dietz Jul 28 '17 at 15:25
  • This thread gives query UPDATE Q SET Q.TITLE = 'TEST' FROM HOLD_TABLE Q WHERE Q.ID = 101; How come it is not working for me? – AAjit Jul 28 '17 at 15:42
  • @AAjit , you saw the thread, and it's to solve a problem for Sql server. Is you RDBMS sql server? – Renato Afonso Jul 28 '17 at 15:44
  • I am currently learning SQL from w3schools and creating tables on it. After searching a bit, they are using RDBMS but not sure which database system it is? – AAjit Jul 28 '17 at 15:49

1 Answers1

0

You use from clause only if you update your table with data from other table. If not just:

UPDATE Person
   SET FirstName='ram'
Grzegorz Grabek
  • 960
  • 7
  • 16
  • This should run, but ideally there would be a `WHERE` clause to make sure the update doesn't rename everyone to `ram`. – Tim Biegeleisen Jul 28 '17 at 15:31
  • 3
    It's common knowledge that this day and age everyone is ram, @TimBiegeleisen – Jens Jul 28 '17 at 15:32
  • Here is thread which gives syntax for updating table with alias. https://stackoverflow.com/questions/4981481/how-to-write-update-sql-with-table-alias-in-sql-server-2008 – AAjit Jul 28 '17 at 15:36
  • This thread gives query UPDATE Q SET Q.TITLE = 'TEST' FROM HOLD_TABLE Q WHERE Q.ID = 101; How come it is not working for me? – AAjit Jul 28 '17 at 15:39
  • 1
    @AAjit That syntax is correct for SQL Server. If you're getting an error on w3schools, just ignore it. W3schools can be good, but doesn't have every compatibility of the real thing. – Aaron Dietz Jul 28 '17 at 15:57
  • Thanks for this. Will test this with real databases. – AAjit Jul 31 '17 at 11:58