0

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'))))
2
Contributors
2
Replies
18
Views
3 Years
Discussion Span
Last Post by deceptikon
0

Improve it how? Make it shorter? Make it faster? Make it more intuitive? You need a specific goal, and "improve it" is not specific at all.

Edited by deceptikon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.