我是SQL的新手,我有三个表:
ALBUMS
album_id | album_name | artist_id | category_id
CATEGORIES
category_id | category_name
ARTISTS
artist_id | artist_name
给定category_name
,如何获得category_id, album_id, album_name, artist_id, artist_name
的结果集?
我尝试了很多JOIN的变体,但我最终得到了更多的结果,而不是缩小结果。这甚至可能吗?
答案 0 :(得分:1)
如果你想要类别“abc”就这样做
Select a.category_id, a.album_id, c.album_name, a.artist_id, a.artist_name
from ALBUMS a
join CATEGORIES b on a.category_id=b.category_id
join ARTISTS c on a.artist_id =c.artist_id
where c.Categoryname='abc'
答案 1 :(得分:1)
select ALBUMS.category_id
, ALBUMS.album_id
, ALBUMS.album_name
, ALBUMS.artist_id
, ARTISTS.artist_name
from ALBUMS
inner join ARTISTS on ALBUMS.artist_id = ARTISTS.artist_id
inner join CATEGORIES on ALBUMS.category_id = CATEGORIES .category_id
where CATEGORIES.category_name = 'Your category name'