Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:


I have a two tables with the same table definitions as follows:

VB
COL1    CO2
1   1000.00
2   2000.00
3   3000.00
4   4000.00
5   5000.00


VB
COL1    CO2
1   1500.00
2   2000.00
3   77000.00
4   80000.00
5   51500.00



By using joins, I need highest salary like as follows:


CO2
800000
Posted
Comments
Thanks7872 1-Apr-15 5:00am    
Use google.
King Fisher 1-Apr-15 5:05am    
you need UNION not Joins.
Maciej Los 1-Apr-15 5:10am    
My virtual 5!
King Fisher 1-Apr-15 5:13am    
Thanks master ;)

Hi,

Check this...

SQL
SELECT MAX(CO2) FROM 
(
SELECT CO2 FROM TBL1
UNION
SELECT CO2 FROM TBL2
)X


Hope this will help you.


Cheers
 
Share this answer
 
As King Fisher[^] mentioned in comment to the question, you - probably - need to use UNION instead of JOIN.

SQL
SELECT MAX(col2)
FROM (
    SELECT col1, col2 
    FROM Table1
    UNION ALL
    SELECT col1, col2
    FROM Table2
) AS T
 
Share this answer
 
v2
Try like this:

1)
SQL
select max(t.col1 )
from  (
    select  *From table3 union all
    select *From table2
)as t 

or
2)
SQL
select top 1 col1
from  (
    select  * From table3 union all
    select * From table2
)as t
order by col1 desc
 
Share this answer
 
v3
Comments
Maciej Los 1-Apr-15 5:20am    
5! My Lord ;)
Member 11366322 1-Apr-15 5:43am    
Hi @King Fisher,
Hope you are doing grate.

Thanks for your solution, but i need solution by using join not using union.
Even i too know the solution by using union.

Thanks and Regards
Bharadwaj
King Fisher 1-Apr-15 5:51am    
So ,you know what is join ? what is union ?
why do you want Join?
Maciej Los 1-Apr-15 5:52am    
So, you need to be more clear and provide more details about joining operation...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900