2012-10-03 45 views
1

。我有這個查詢如何在一個查詢/表中獲取2個字段的唯一值列表?例如

select distinct t1.date1, t2.date2 
from t1 
join t2 ... 
.... 
where ... 

我想獲得這2個日期的唯一值列表。我如何在Firebird 2.5上執行此操作?

我試試這個

with dates as (
select t1.date1 d1, t2.date2 d2 
from t1 
join t2 ... 
.... 
where ...) 
select d1 from dates 
union 
select d2 from dates 

但是這個版本將放緩性能比較兩倍

回答

1

試試這個:

with dates (dt) as (
    select t1.date1 from t1 
    where (1=1) --conditions 

    union 

    select t2.date2 from t2 
    where (1=1) --conditions 
) 

select unique dt 
from dates 
相關問題