2010-08-11 6 views
0

je les tableaux ci-dessous dans ma base de données SQL:Déclaration SQL pour accéder aux données à travers les relations

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 

Je me demande s'il est possible d'obtenir toutes les publicationIds de la authorsJoinTable affichés par ordre year descendant?
Merci à l'avance,
Dean

Répondre

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

+1 .. Aujourd'hui, j'appris "AS" syntaxe n'est pas nécessaire entre un identifiant de table et son alias. :) – sleepynate

+0

Vrai, mais je pense que "AS" améliore la lisibilité (personnellement) ... – ircmaxell

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