How to use max function in such condition? My query is 

select * from guestuser union select * from olduser ORDER BY userid DESC LIMIT 1;



Is that correct query to find last userid from different table have different userid? 
can i change query using max function. or optimize it?


table1 - userid -  1, 4, 5... etc

table2 - userid -  2, 3, 6...etc
Try it this way:

select userid from (
(select userid from guestuser order by userid DESC LIMIT 1)
union all 
(select userid from olduser ORDER BY userid DESC LIMIT 1)
) sq 
order by userid DESC LIMIT 1;