Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select the max value from multiple tables in one column

Tags:

sql

oracle

I would like to get the last date of records modified. Here is a sample simple SELECT:

SELECT
 t01.name,
 t01.last_upd date1,
 t02.last_upd date2,
 t03.last_upd date3,
 'maxof123' maxdate
FROM
  s_org_ext   t01,  
  s_org_ext_x   t02,   
  s_addr_org   t03   
WHERE
  t02.par_row_id(+)= t01.row_id and
  t03.row_id(+)= t01.pr_addr_id and
  t01.int_org_flg = 'n';

How can I get column maxdate to display the max of the three dates?

Note: no UNION or sub/nested SELECT statements ;)

like image 835
Derick Schoonbee Avatar asked Dec 12 '22 23:12

Derick Schoonbee


1 Answers

Greatest (t01.last_upd, t02.last_upd date2, t03.last_upd ) as maxdate

like image 85
heisenberg Avatar answered Apr 29 '23 14:04

heisenberg