Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MAX Value

Author  Topic 

sadbjp
INNER JOIN

41 Posts

Posted - 2007-05-14 : 10:19:11
Hi,

I have two tables A and B with column LastUpdate common to both. How can I find the maximum value of LastUpdate with tables A and B?

Thanks in advance.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 10:22:37
select max(lastupdate) from (select lastupdate from table1 union all select lastupdate from table2) as d


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 2007-05-14 : 10:24:22
WHat does "d" means here?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-14 : 10:27:14
It is called derived table
Read it in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 10:27:43
You can use any letter available...
It is just a name for the derived table I created in the query.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 10:27:59



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 2007-05-14 : 10:29:02
What if I want to store the maximum value of LastUpdate i na varaible called "m". Then how can I proceed?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 10:31:13
select max(lastupdate) as m from (select lastupdate from table1 union all select lastupdate from table2) as d


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 10:32:13
declare @m int

select @m = max(lastupdate) from (select lastupdate from table1 union all select lastupdate from table2) as d


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-14 : 10:34:11
quote:
Originally posted by sadbjp

What if I want to store the maximum value of LastUpdate i na varaible called "m". Then how can I proceed?


m cant be a variable but @m

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 2007-05-14 : 10:39:12
Thanks a lot guys. You are so helpful!
Go to Top of Page
   

- Advertisement -