LoginSignup
9
7

More than 5 years have passed since last update.

MySQLのテーブル内のメールアドレスのドメイン部分を一括置換するクエリ

Posted at

hoge テーブルの mail 列のドメインを fuga.com に置換するばあい。

UPDATE
  `hoge`
SET
  `mail` = CONCAT(
      LEFT(
          `mail`,
          INSTR(`mail`, '@')
      ),
      'fuga.com'
  )
WHERE
  `mail` NOT LIKE '%@fuga.com';

INSTR()mail 列の @ の出現位置を取得し、
LEFT()mail の先頭から @ までの位置の文字列を抜き出し、
CONCAT()fuga.com と結合したものをSETする感じです。

参考

Mysql-how to update the “domain.com” in “address@domain.com”

9
7
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
9
7