我有两个 sql 查询如下
SELECT rc.stateId,rs.stateName FROM
(SELECT DISTINCT cityid FROM HolidayPackageCity) AS hpc
INNER JOIN
(SELECT cityid,stateid FROM RegCity WHERE countryCode='IN' AND stateId IS NOT NULL) AS rc
ON hpc.cityId=rc.cityId
INNER JOIN
RegState AS rs
ON rc.stateId=rs.stateId
对比
SELECT DISTINCT rc.stateId,rs.stateName
FROM HolidayPackageCity AS hpc
INNER JOIN
RegCity AS rc
ON hpc.cityId=rc.cityId
INNER JOIN
RegState AS rs
ON rc.stateId=rs.stateId
WHERE rc.countryCode='IN' AND rc.stateId IS NOT NULL
在第一个查询中,我首先过滤特定表的数据,然后应用连接,在第二个表中,我首先应用连接,然后应用 where 条件过滤数据。我想知道的是哪一个更快,为什么。