0
SELECT TOP 1 * FROM 
(
    select max(updatedtimestamp) from db1.dbo.policyrepresentationcache with(nolock)
    UNION
    select max(updatedtimestamp) from db2.dbo.policyrepresentationcache with(nolock)
    ) 
ORDER BY updatedtimestamp

I'm running into syntax errors here and im not sure how to set it up.

4

2 回答 2

3

您只是缺少联合生成的表的别名。我已将其别名为以下

SELECT TOP 1 a.updatedtimestamp FROM
(
     select max(updatedtimestamp) as updatedtimestamp  
     from db1.dbo.policyrepresentationcache with(nolock)
     UNION
     select max(updatedtimestamp) 
     from db2.dbo.policyrepresentationcache with(nolock)
) a
ORDER BY a.updatedtimestamp
于 2012-10-17T22:23:12.900 回答
0
SELECT TOP 1 Temp.* FROM 
(
    select max(updatedtimestamp) from db1.dbo.policyrepresentationcache with(nolock)
    UNION
    select max(updatedtimestamp) from db2.dbo.policyrepresentationcache with(nolock)
    ) AS Temp
ORDER BY Temp.updatedtimestamp
于 2012-10-17T22:25:33.203 回答