たとえば「信長」という名称の本、「秀吉」という名称の本のいずれかを出版している出版社を探したい時、
```sql
select p.name from publisher p
left join book b on b.publisher_id = p.id
where b.name = '信長' or b.name = '秀吉' group by p.id;
こんな風に書けますが、 「信長」という名称の本、「秀吉」という名称の本、両方出版している出版社を探すにはどのように書いたら良いのでしょうか。 ```sql select p.name from publisher p left join book b on b.publisher_id = p.id where b.name = '信長' and b.name = '秀吉' group by p.id;
当たり前ですが、こう書き換えただけではダメです。
create tableは
出版社テーブル create table publisher ( id serial primary key, name text ); 本テーブル create table book ( id serial primary key, publisher_id integer, name text );
となります。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/29 04:17