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 from Multiple tables

Author  Topic 

chiman

21 Posts

Posted - 2007-11-12 : 16:16:10
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

38200 Posts

Posted - 2007-11-12 : 16:28:14
[code]
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
[/code]

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

chiman

21 Posts

Posted - 2007-11-12 : 16:29:34
Thanks a lot. This worked!


Go to Top of Page
   

- Advertisement -