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 from Multiple tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chiman
Starting Member

21 Posts

Posted - 11/12/2007 :  16:16:10  Show Profile  Reply with Quote
hi,
I have a query like below,

select max(batchNumber ) from Adjustments where store_Id = 8637
Union
select max(batchnumber) from batch b
inner join Document d on
d.Document_Id = b.General_Id and b.BatchType <> 'Warehouse' and b.TranTable='Document'

This gives me 2 rows,how ever i want the max on the result of this union.

Assume, the above returns
10
20

i want 20.

how to go about this?


Thanks

tkizer
Almighty SQL Goddess

USA
35937 Posts

Posted - 11/12/2007 :  16:28:14  Show Profile  Visit tkizer's Homepage  Reply with Quote

select max(batchNumber)
from
(
	select max(batchNumber) as batchNumber
	from Adjustments 
	where store_Id = 8637
	union all
	select max(batchnumber) 
	from batch b
	inner join Document d 
	on d.Document_Id = b.General_Id
	where b.BatchType <> 'Warehouse' and b.TranTable = 'Document'
) t


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

chiman
Starting Member

21 Posts

Posted - 11/12/2007 :  16:29:34  Show Profile  Reply with Quote
Thanks a lot. This worked!


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.05 seconds. Powered By: Snitz Forums 2000