ChrisB
ChrisB

Reputation: 11

OrientDB SQL - Update with subquery

I want to copy the @rid of Table2 into a field "r1" of Table1, where Table2.f1=Table1.f2 (f1 & f2 just two other fields).

The only solution I came up with is this:

UPDATE Table1 SET r1=(SELECT @rid FROM Table2 
WHERE Table2.f1=$parent.$current.f2)

But it returns a string with the entire field/value list. So I have to trim it as follows:

UPDATE Table1 SET r1=r1.substring(6,12) 

(to keep just the @rid part)

But it seems to me that there has to be a better/more elegant solution, with a single query.

Is there a way to extract only the @rid from the above field list?

I also tried Omega Silva's solution, which does not seem to work. This is the error I get.

Any ideas?

Upvotes: 0

Views: 327

Answers (1)

Alessandro Rota
Alessandro Rota

Reputation: 3570

I don't know if I understand correctly but I tried with this little example

enter image description here

and with

UPDATE Table1 SET r1=(SELECT @rid FROM Table2 WHERE f1=$parent.$current.f2)

I got

enter image description here

Hope it helps.

Upvotes: 0

Related Questions