Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have created two tables namely indledger and cash_indledger which has two same column namely "entryno".Now i want the maximum of "entryno" ie. max(entryno) from these two tables collectively in a single query....
Please help me....
Thank you.
Posted

Use UNION

SQL
SELECT MAX(entryno) AS m FROM tbl1
UNION
SELECT MAX(exitno) AS m FROM tbl2
 
Share this answer
 
Comments
Yashodip Jagdale 24-Jun-11 5:22am    
But sir I want max from two tables of same column name.
Kim Togo 24-Jun-11 5:34am    
SELECT MAX(m)
FROM (
SELECT MAX(entryno) AS m FROM tbl1
UNION
SELECT MAX(exitno) AS m FROM tbl2)
Espen Harlinn 25-Jun-11 13:43pm    
A 5
Kim Togo 27-Jun-11 3:35am    
Thanks Espen
SQL
SELECT CASE WHEN MAX(indledger.entryno) > MAX(cash_indledger.entryno) THEN MAX(indledger.entryno) ELSE MAX(cash_indledger.entryno) END FROM indledger, cash_indledger;
 
Share this answer
 
Comments
Yashodip Jagdale 24-Jun-11 5:57am    
But sir any one of these two tables has no data then it return NULL.Please help me sir..
CPallini 24-Jun-11 6:00am    
You should be able to handle NULL values, shouldn't you?

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