2010-08-11 36 views
0

數據我有我的SQL數據庫下表:SQL語句訪問整個關係

authors: 
    name varchar 
    id int Primary Key 
publications: 
    id int Primary Key 
    title mediumtext 
    year int 
authorsJoinTable: 
    authorId -> Foreign Key to the authors table 
    publicationID -> Foreign Key to the publications Table 
    sequenceId int 

我想知道是否有可能獲得所有從authorsJoinTablepublicationIds下令year下降?
由於事先
院長

回答

2
SELECT publicationID 
FROM authorsJoinTable a JOIN publications p 
    ON (p.Id = a.publicationId) 
ORDER BY p.Year DESC 
+0

+1 ..今天我才知道「AS」不需要表標識符和它的別名之間的語法。 :) – sleepynate 2010-08-11 14:39:46

+0

是的,但我認爲'AS'提高了可讀性(個人)... – ircmaxell 2010-08-11 14:47:28

0
SELECT publicationID FROM authorsJoinTable JOIN publications AS P ON P.id = publicationID ORDER BY P.year DESC