0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQL JOIN句を使ったUPDATE

Last updated at Posted at 2019-08-29

JOINを使用したUPDATE文

MySQL使用時は問題なかった構文がPostgreSQLでが構文エラーになってしまったので、
備忘録。

以下、流したSQL
構文はMySQL時には実行できていた書き方
postgreSQLでは構文エラー

MySQL
UPDATE
  tbl_a A
SET 
  A.set_rating_status = '1'
JOIN 
  tbl_b B ON B.contents = A.contents
JOIN
  tbl_c C ON C.id = B.id
JOIN
  tbl_d D ON D.name = C.name
WHERE 
  A.cid NOT IN (SELECT cid FROM tbl_e)
AND
  D.delete_flg = '0';

以下に成型してエラー解消し、実行できた。
慣れない。。。
ややこしい。。

postgreSQL
UPDATE
  tbl_a
SET
  set_status = '1'
FROM 
  tbl_b B
JOIN 
  tbl_c C ON C.id = B.id
JOIN
  tbl_d D ON D.name = C.name
WHERE
  B.contents = tbl_a.contents
AND
  tbl_a.cid NOT IN (SELECT cid FROM tbl_e)
AND
  D.delete_flg = '0';
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?