2009年4月1日水曜日

複数列一括比較 (行値構成子)

Microsoft SQL Server では[行値構成子]は実装されていない (SQLServer 2008 Express)

SELECT TA.*
FROM TA
WHERE (key1,Key2,Key3)
(SELECT Key1,Key2, MAX(Key3) FROM TA WHERE .... GROUP BY Key1,Key2 )

とりあえず

SELECT TA.*
FROM TA
INNER JOIN
(SELECT Key1,Key2,MAX(Key3) as Key3 FROM TA WHERE .... GROUP BY Key1,Key2 ) AS TB
ON (TA.Key1=TB.Key1 AND TA.Key2=TB.Key2 AND TA.Key3=TB.Key3)