将JOIN和隐式JOIN转换为对应的显式JOIN

时间:2018-02-08 03:24:52

标签: sql sqlite

我试图将下面查询的内部子查询转换为显式 JOIN

SELECT *
FROM `files`
WHERE `version` = (
    SELECT `temp`.`version`
    FROM `files` AS `temp`
    WHERE `temp`.`location` = `files`.`location`
    AND temp.name = `files`.name
    ORDER BY `temp`.`version` DESC
    LIMIT 1
)
ORDER BY `location`, `name`

我尝试了以下操作,但最终得到的结果集不正确:

SELECT *
FROM `files`
WHERE `version` = (
    SELECT `temp`.`version`
    FROM `files` AS `temp`
    JOIN files ON `temp`.`location` = `files`.`location` AND temp.name = `files`.name
    ORDER BY `temp`.`version` DESC
    LIMIT 1
)
ORDER BY `location`, `name`

我如何在SQLite中执行此操作?

0 个答案:

没有答案