0

2 つの Select 句と UNION を組み合わせたクエリがあります。先頭の最初の行のみを選択したいです。Union を使用してそれを行うにはどうすればよいですか?

Select Fault,OccurredOn From ATMStatus Where Ticket=189703 // This Will retrieve single record as the primary key is applied
Union 
Select Fault,OccurredOn From ATMStatusHistory Where Resolved=0 AND Ticket=189703 Order By OccurredOn Desc
4

2 に答える 2

2
select top 1 * from 
(
                 Select Fault,OccurredOn 
                 From ATMStatus
                 Where Ticket=189703
                 Union 
                 Select Fault,OccurredOn
                 From ATMStatusHistory
                 Where Resolved=0 AND Ticket=189703
) x
Order By OccurredOn Desc
于 2012-08-07T12:14:54.973 に答える
0

これは 2 行を返します。

select 1 as id
union
select 2 as id

これは 1 行を返します。

select top 1 * from (
  select 1 as id
  union
  select 2 as id
) as x
order by id
于 2012-08-07T12:15:38.040 に答える