I have 3 tables:
1st Table - Staff
:
------------------------------------
| person_id | name | studio_id |
|-----------|----------|-----------|
| 1 | Bill | 1 |
| 2 | Kate | 1 |
------------------------------------
2nd Table - Studio
:
-----------------------------
| studio_id | studio_name |
|-----------|---------------|
| 1 | PeopleProd |
| 2 | TheBest |
-----------------------------
3rd Table - Album
:
-----------------------------------
| album_id | Name | studio_id |
|----------|----------|-----------|
| 1 | Hits | 1 |
| 2 | Goldset | 1 |
-----------------------------------
I want to display them in one row, so the result will be:
------------------------------------------------------
| studio_id | studio_name | person_name | album_name |
|-----------|-------------|-------------|------------|
| 1 | PeopleProd | Bill | Hits |
| 1 | PeopleProd | Kate | GoldSet |
------------------------------------------------------
But when I'm using the JOIN
query, I'm receiving duplicates:
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`.
How can this be fixed?
Now the output:
------------------------------------------------------
| studio_id | studio_name | person_name | album_name |
|-----------|-------------|-------------|------------|
| 1 | PeopleProd | Bill | Hits |
| 1 | PeopleProd | Kate | Hits |
| 1 | PeopleProd | Bill | GoldSet |
| 1 | PeopleProd | Kate | GoldSet |
------------------------------------------------------