0

我有两张桌子:乐队和专辑。这是结构

乐队:id_band 名称

专辑 id_album id_band 名称

所以,我需要一个查询来显示最后插入乐队的所有专辑。

我试试这个:

SELECT bands.name, albums.name
FROM bands
JOIN albums ON albums.id_band = bands.id_band
ORDER BY bands.id_band DESC
LIMIT 1

但我只得到第一张专辑。并非最后插入乐队的所有专辑。我该如何解决?

4

2 回答 2

2
SELECT b.name, a.name
FROM (SELECT name, id_band
    FROM bands
    ORDER BY id_band DESC
    LIMIT 1) AS b
JOIN albums a ON a.id_band = b.id_band 
于 2013-01-22T17:59:04.833 回答
0

询问:

SELECT b.name,
       a.name
FROM bands b
JOIN albums a ON a.id_band = b.id_band
WHERE b.id_band = (SELECT max(id_band)
                   FROM bands)
于 2013-01-22T21:51:42.287 回答