10
7

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.

mysqldumpでwhereにjoinを使う

Posted at

環境:MySQL5.6, InnoDB

mysqldumpは、--whereオプションを指定して条件に当てはまるデータのみ取得することができる。
4.5.4 mysqldump — データベースバックアッププログラム

このwhereオプション内でjoinを使いたい。

例:
books(id, title, author_id)
authors(id, name, age)
の2つのテーブルがあって、mysqldumpを使ってbooksのデータを取得したい。
ただし、その対象はauthorsのageが40以上のもののみ。

mysqldump -u user_name -p -h host_name --single-transaction --where "id in (select books.id from books inner join authors on books.author_id = authors.id where authors.age >= 40)"

このように指定することで、joinを使った条件を指定できた。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?