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

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
DirWolf
  • 834
  • 6
  • 22
  • 3
    Replace `UPDATE AlfaGood` with `UPDATE ag`. – Larnu Dec 31 '19 at 10:25
  • 1
    *"missing (; | ,) before FROM"*? That isn't a SQL Server error. SQL Server doesn't use Pipes (`|`). – Larnu 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. – Larnu 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) – Larnu 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
  • 47,993
  • 9
  • 26
  • 51
Gauravsa
  • 5,847
  • 2
  • 16
  • 25