SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MAX Value
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sadbjp
INNER JOIN

41 Posts

Posted - 05/14/2007 :  10:19:11  Show Profile  Reply with Quote
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

Sweden
30265 Posts

Posted - 05/14/2007 :  10:22:37  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 05/14/2007 :  10:24:22  Show Profile  Reply with Quote
WHat does "d" means here?
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 05/14/2007 :  10:27:14  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

Sweden
30265 Posts

Posted - 05/14/2007 :  10:27:43  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

Sweden
30265 Posts

Posted - 05/14/2007 :  10:27:59  Show Profile  Visit SwePeso's Homepage  Reply with Quote



Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sadbjp
INNER JOIN

41 Posts

Posted - 05/14/2007 :  10:29:02  Show Profile  Reply with Quote
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

Sweden
30265 Posts

Posted - 05/14/2007 :  10:31:13  Show Profile  Visit SwePeso's Homepage  Reply with Quote
select max(lastupdate) as m from (select lastupdate from table1 union all select lastupdate from table2) as d


Peter Larsson
Helsingborg, Sweden

Edited by - SwePeso on 05/14/2007 10:31:30
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30265 Posts

Posted - 05/14/2007 :  10:32:13  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
22761 Posts

Posted - 05/14/2007 :  10:34:11  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 - 05/14/2007 :  10:39:12  Show Profile  Reply with Quote
Thanks a lot guys. You are so helpful!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000