0

I'm trying to make an update query with a join statement. however, it keeps throwing an error of syntax I'm not really sure where am I going wrong here cause I think I have done it right.

UPDATE AlfaGood 
SET ag.name = 'New text goes here' 
FROM AlfaGood ag 
INNER JOIN SecondAlfa ca ON ca.id = 1 
                         AND ag.agrid = 'Thats my original text';

Please advise on the above if possible. I get an error

ORA-00933: SQL command not properly ended

saying it's missing (; | ,) before FROM

DirWolf
  • 871
  • 6
  • 22
  • 3
    Replace `UPDATE AlfaGood` with `UPDATE ag`. – Thom A Dec 31 '19 at 10:25
  • 1
    *"missing (; | ,) before FROM"*? That isn't a SQL Server error. SQL Server doesn't use Pipes (`|`). – Thom A Dec 31 '19 at 10:26
  • 1
    Oracle SQL Developer is an IDE, not an RDBMS. I've corrected the tags for now what we have found out what is really the RDBMS you are using. – Thom A Dec 31 '19 at 10:31
  • Update statement with joins are pretty much incomprehensible on Oracle, better off using a cursor or client side code – gjvdkamp Dec 31 '19 at 10:32
  • 3
    Does this answer your question? [Update statement with inner join on Oracle](https://stackoverflow.com/q/2446764/3484879) – Thom A Dec 31 '19 at 10:33
  • Alright ... so I better update it manually! Thank you for your advice. I was wondering why not working cause I made this on normal SQL server so many times but in this job, I'm using Oracle SQL Dev – DirWolf Dec 31 '19 at 10:34
  • 1
    For future reference, Oracle UPDATE syntax is described here: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/UPDATE.html – William Robertson Dec 31 '19 at 10:49

1 Answers1

2

You can do this:

UPDATE AlfaGood ag
   SET ag.name = 'New text goes here' 
--FROM AlfaGood ag -- not an Oracle syntax
 WHERE ag.agrid = 'Thats my original text' 
   AND ag.id = 1 
   AND EXISTS ( SELECT ca.id FROM SecondAlfa ca WHERE ca.id = 1 );
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Gauravsa
  • 6,330
  • 2
  • 21
  • 30