Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you can union them together and then order the output by the last_updated_dt in descending order and just limit the output to 1. </p> <pre><code>SELECT employee_id, last_updated_dt, last_updated_by FROM (SELECT employee_id, last_updated_dt, last_updated_by FROM employee UNION SELECT employee_id, last_updated_dt, last_updated_by FROM employee_award UNION SELECT employee_id, last_updated_dt, last_updated_by FROM employee_address ) last WHERE employee_id = 1 ORDER BY last_updated_dt DESC LIMIT 1 </code></pre> <p>To make it more efficient you'd probably want to put the criteria in the UNION subquery.</p> <pre><code>SELECT employee_id, last_updated_dt, last_updated_by FROM (SELECT employee_id, last_updated_dt, last_updated_by FROM employee WHERE employee_id = 1 UNION SELECT employee_id, last_updated_dt, last_updated_by FROM employee_award WHERE employee_id = 1 UNION SELECT employee_id, last_updated_dt, last_updated_by FROM employee_address WHERE employee_id = 1 ) last ORDER BY last_updated_dt DESC LIMIT 1 </code></pre> <p>As correctly pointed out in the comments, the above solutions only work in MySQL, not Oracle. Here's a version that should work in Oracle.</p> <pre><code>SELECT DISTINCT employee_id, FIRST_VALUE(last_updated_dt) OVER (ORDER BY last_updated_dt DESC), FIRST_VALUE(last_updated_by) OVER (ORDER BY last_updated_dt DESC) FROM (SELECT employee_id, last_updated_dt, last_updated_by FROM employee WHERE employee_id = 1 UNION SELECT employee_id, last_updated_dt, last_updated_by FROM employee_award WHERE employee_id = 1 UNION SELECT employee_id, last_updated_dt, last_updated_by FROM employee_address WHERE employee_id = 1 ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload