in Education by
I have a table in Db2 called myTable. It has several columns: a | b | date1 | date2 --------------------------------------------- 1 abc 2014-09-02 2 aax 2015-12-30 2016-09-02 2 bax 2015-10-20 2 ayx 2014-12-10 2016-02-12 As seen from values above, date1 and date2 can have null values as well. How can I get the max of both date1 and date2 together ? i.e. the output of the query should be 2016-09-02 as that is the max date of all the dates present in date1 and date2. I am using Db2-9. Thanks for reading! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
How about using a UNION query: SELECT MAX(t.newDate) FROM ( SELECT date1 AS newDate FROM myTable UNION SELECT date2 AS newDate FROM myTable ) t Another option: SELECT CASE WHEN t.date1 > t.date2 THEN t.date1 ELSE t.date2 END FROM ( SELECT (SELECT MAX(date1) FROM myTable) AS date1, (SELECT MAX(date2) FROM myTable) AS date2 FROM SYSIBM.SYSDUMMY1 ) t

Related questions

0 votes
    I have a table in Db2 called myTable. It has several columns: a | b | date1 | date2 ----- ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have a table in Db2 called myTable. It has several columns: a | b | date1 | date2 ----- ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    Lets say I have this following table: +------+-------------------------+-- ... JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    It's easy to find duplicates with one field: SELECT name, COUNT(email) FROM users GROUP BY email HAVING COUNT( ... to find them first. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 00: ... How can I get that? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I'm getting unexpected results for getting the collections between two columns. I have this simple collection: ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I'm getting unexpected results for getting the collections between two columns. I have this simple collection: ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    What is the difference between the EXISTS and IN clause in SQL? When should we use EXISTS, and when should we use IN? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    What is the difference between the EXISTS and IN clause in SQL? When should we use EXISTS, and when should we use IN? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I am trying to run the following SQL: INSERT INTO Suppliers ( [SupplierID], [CompanyName]) Select [SupplierID], [ ... is very slow. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    Both these joins will give me the same results: SELECT * FROM table JOIN otherTable ON table.ID = ... different SQL implementations? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Difference between inner and outer join. i am using two table and want to fetch data from both table so which ... can solve our problem Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    What is the difference between UNION and UNION ALL? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    Difference between inner and outer join. i am using two table and want to fetch data from both table so which ... solve our problem. Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    What is the difference between DELETE and TRUNCATE statements?...
asked Dec 11, 2020 by JackTerrance
...