I want to get the maximum Column5 from both the table and then the maximum Column3 from the table which has max Column5.
I don't know if it is the right forum and also am not good in sql :(
SELECT max(Column5_1)
FROM
(SELECT max(Column5) Column5_1
FROM TABLE1
WHERE Column4 = -1
AND Column1 = 'STRING1'
AND Column2 = 'STRING2'
AND Column3 >=
(SELECT max(Column3_2)
FROM
(SELECT max(Column3_1) Column3_2
FROM
(SELECT max(Column3) Column3_1
FROM TABLE1
WHERE Column4 = -1
AND Column1 = 'STRING1'
AND Column2 = 'STRING2'
UNION ALL SELECT max(Column3) Column3_1
FROM TABLE2
WHERE Column4 = -1
AND Column1 = 'STRING1'
AND Column2 = 'STRING2')))
UNION ALL SELECT max(Column5) Column5_1
FROM TABLE2
WHERE Column4 = -1
AND Column1 = 'STRING1'
AND Column2 = 'STRING2'
AND Column3 >=
(SELECT max(Column3_2)
FROM
(SELECT max(Column3_1) Column3_2
FROM
(SELECT max(Column3) Column3_1
FROM TABLE1
WHERE Column4 = -1
AND Column1 = 'STRING1'
AND Column2 = 'STRING2'
UNION ALL SELECT max(Column3) Column3_1
FROM TABLE2
WHERE Column4 = -1
AND Column1 = 'STRING1'
AND Column2 = 'STRING2'))))