views:

19

answers:

2

Hi everybody, i had the tables structure like below

Table1
-------
Id SessionNo
1  1
2  2
3  2

Table2
-------
Id SessionNo
1  1
2  3
3  3

Table3
-------
Id SessionNo
1  1
2  3
3  4

from these three tables i need the output as

SessionNo 4

please give me a query for this

+3  A: 
SELECT MAX(maxNo)
FROM (
    SELECT MAX(SessionNo) maxNo FROM Table1
    UNION
    SELECT MAX(SessionNo) maxNo FROM Table2
    UNION
    SELECT MAX(SessionNo) maxNo FROM Table3
) r
Scoregraphic
+2  A: 

A possible solution would be (dunno if it is the best).

select max(SessionNo) 
from    
  ( 
     select SessionNo
     from Table1
     union all
     select SessionNo
     from Table2
     union all
     select SessionNo
     from Table3
  )
Cid54
`UNION ALL` is unnecessary when you are applying `MAX()` to the result anyway. ;)
Tomalak
Idd, but as a quick solution it will suffice.
Cid54