sql server - select max and min from multiple tables -
i using sql server 2012. have 2 tables contain dates. want query max , min dates both tables. know line below give me max , min dates 1 table.
select max(dttime), min(dttime) tableone
what want min of 2 max dates table 1 , 2 & max of 2 min dates table. please see example below.
tableone tabletwo max date 6-june-2000 23-june-2002 min date 10-jan-1980 15-feb-1982
result returned,
max date = 6-june-2000 min date = 15-feb-1982
you can use union, , select minimum max values , max minimum values:
select min(mx), max(mn) ( select max(dttime) `mx`, min(dttime) `mn` tableone union select max(dttime) `mx`, min(dttime) `mn` tabltow ) t1
Comments
Post a Comment