所以你需要的是两个INNER JOIN
s 靠在VehicleSpecs
桌子上,每个sCar_Id1
和Car_Id2
. 我已将它们别名为car1, car2
.
SELECT TOP 100
c.Id,
c.Slug,
c.TimeStamp,
/* Select the relevant columns from *both* of the joined tables */
/* And give each column an alias to differentiate it from the other */
car1.Year AS car1Year,
car1.Make AS car1Make,
car1.Model AS car1Model,
car2.Year AS car2Year,
car2.Make AS car2Make,
car2.Model AS car2Model
FROM
Comparisons c
/* Join first against VehicleSpecs for Car_Id1 */
INNER JOIN VehicleSpecs car1 ON c.Car_Id1 = car1.Id
/* Then once more for Car_Id2 */
INNER JOIN VehicleSpecs car2 ON c.Car_Id2 = car2.Id
ORDER BY c.TimeStamp
你说你想要最新的,所以我假设你实际上是指在时间戳上使用降序:
ORDER BY c.TimeStamp DESC