Iはテーブルを有する:表示異なるテーブルデータ
第1表 - Staff
:
------------------------------------
| person_id | name | studio_id |
|-----------|----------|-----------|
| 1 | Bill | 1 |
| 2 | Kate | 1 |
------------------------------------
2表 - Studio
:
-----------------------------
| studio_id | studio_name |
|-----------|---------------|
| 1 | PeopleProd |
| 2 | TheBest |
-----------------------------
3位表 - Album
:
-----------------------------------
| album_id | Name | studio_id |
|----------|----------|-----------|
| 1 | Hits | 1 |
| 2 | Goldset | 1 |
-----------------------------------
私が一列にそれらを表示したいので、結果は次のようになります。
------------------------------------------------------
| studio_id | studio_name | person_name | album_name |
|-----------|-------------|-------------|------------|
| 1 | PeopleProd | Bill | Hits |
| 1 | PeopleProd | Kate | GoldSet |
------------------------------------------------------
しかし、私はJOIN
クエリを使用しています、私は重複を受けています:
SELECT studio_id studio_name person_name album_name
FROM Studio s
JOIN Album a ON s.studio_id = a.studio_id
JOIN Staff ss ON s.studio_id = ss.studio_id`.
これをどのように修正できますか?
今すぐ出力:あなたは出力を見れば
------------------------------------------------------
| studio_id | studio_name | person_name | album_name |
|-----------|-------------|-------------|------------|
| 1 | PeopleProd | Bill | Hits |
| 1 | PeopleProd | Kate | Hits |
| 1 | PeopleProd | Bill | GoldSet |
| 1 | PeopleProd | Kate | GoldSet |
------------------------------------------------------
をあなたはどのようなSQLのバリエーションを使用していますか? – yanman1234
mssql server 2008 – Martin
なぜ 'Bill'は' Hits'しか取得できないのですか?代わりに 'GoldSet'を使用しないでください –