I try to make a query with inner join from grass gis (but in that community this question was concerned as offtopic, so it seems to concern only SQL lite):
db.execute sql="UPDATE A SET A.next2=B.next_stream
FROM stream_order2 AS A
INNER JOIN stream_order2 AS B ON A.factor=B.stream"
I have to do this because I would like to set values of next2 as values of next stream from table corresponding to stream numbers equal to factor value. db.execute throws an error.
Then I updated the command and removed A. statement. Now the error is:
Error in sqlite3_prepare():
near "FROM": syntax error
I tried to remove A. after ON, but it doesn't help, I don't think it's the issue.
1 Answer 1
I have SQLite version 3.27.2 2019年02月25日 16:06:06
UPDATE FROM is supported beginning in SQLite version 3.33.0 (2020年08月14日).
You can get around this by using a correlated subquery and having suitable indexes ,
UPDATE stream_order2
SET next2 = (SELECT B.next_stream
FROM stream_order2 B
WHERE B.stream=stream_order2.factor )
WHERE EXISTS ( SELECT 1
FROM stream_order2 B
WHERE B.stream=stream_order2.factor)
See example here
-
It works. Thanks.Nikolay Yasinskiy– Nikolay Yasinskiy2023年09月05日 12:32:24 +00:00Commented Sep 5, 2023 at 12:32
-
Yes, sorry, I have forgotten. I am awareNikolay Yasinskiy– Nikolay Yasinskiy2023年09月05日 13:30:32 +00:00Commented Sep 5, 2023 at 13:30
update from
syntax is supported from v3.33 version ?SQLite version 3.28.0 2019年04月15日 14:49:49