Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL get LAST record for each ID after some Date
    text
    copied!<p>I need help creating a SQL statement for retrieving LAST record after some date for each USERID in USER_LOG table. </p> <p>I forgot to write there are few other columns in this table.</p> <p><strong><code>TABLE: USER_LOG</code></strong></p> <pre> ID NAME MODIFY_DATE MODIFY_TYPE 55 userA 2013-05-07 15:47:53.0 1 88 userB 2013-05-07 16:00:57.0 1 55 userA 2013-05-08 11:44:10.0 2 88 userB 2013-05-08 15:47:09.0 2 88 userB 2013-05-08 16:01:41.0 1 55 userA 2013-05-09 15:11:53.0 0 55 userA 2013-05-09 16:00:57.0 0 55 userA 2013-05-10 09:14:10.0 1 88 userB 2013-05-10 16:01:41.0 2 55 userA 2013-05-10 18:23:03.0 2 55 userA 2013-05-11 09:14:10.0 2 88 userB 2013-05-11 16:01:41.0 1 55 userA 2013-05-13 11:34:07.0 1 55 userA 2013-05-13 15:53:04.0 2 55 userA 2013-05-13 16:13:04.0 1 </pre> <pre><code>Example 1: Get All users they have bean changed after '2013-05-08 00:00:00.0'. Must return: </code></pre> <pre> ID NAME MODIFY_DATE MODIFY_TYPE 55 userA 2013-05-07 15:47:53.0 1 88 userB 2013-05-07 16:00:57.0 1 55 userA 2013-05-08 11:44:10.0 2 88 userB 2013-05-08 15:47:09.0 2 88 userB 2013-05-08 16:01:41.0 1 55 userA 2013-05-09 15:11:53.0 0 55 userA 2013-05-09 16:00:57.0 0 55 userA 2013-05-10 09:14:10.0 1 88 userB 2013-05-10 16:01:41.0 2 55 userA 2013-05-10 18:23:03.0 2 55 userA 2013-05-11 09:14:10.0 2 **88 userB 2013-05-11 16:01:41.0 1** RETURN THIS 55 userA 2013-05-13 11:34:07.0 1 55 userA 2013-05-13 15:53:04.0 2 **55 userA 2013-05-13 16:13:04.0 1** RETURN THIS </pre> <pre><code>Example 2: Get All users they have bean changed after '2013-05-12 00:00:00.0'. Must return: </code></pre> <pre> ID NAME MODIFY_DATE MODIFY_TYPE 55 userA 2013-05-07 15:47:53.0 1 88 userB 2013-05-07 16:00:57.0 1 55 userA 2013-05-08 11:44:10.0 2 88 userB 2013-05-08 15:47:09.0 2 88 userB 2013-05-08 16:01:41.0 1 55 userA 2013-05-09 15:11:53.0 0 55 userA 2013-05-09 16:00:57.0 0 55 userA 2013-05-10 09:14:10.0 1 88 userB 2013-05-10 16:01:41.0 2 55 userA 2013-05-10 18:23:03.0 2 55 userA 2013-05-11 09:14:10.0 2 88 userB 2013-05-11 16:01:41.0 1 55 userA 2013-05-13 11:34:07.0 1 55 userA 2013-05-13 15:53:04.0 2 **55 userA 2013-05-13 16:13:04.0 1** RETURN THIS </pre> <p>I found something but I don't know where we put the condition with date after X:</p> <p><code> SELECT u1.* FROM user_log u1 LEFT JOIN user_log u2 ON (u1.id = u2.id AND u1.modify_date &lt; u2.modify_date ) WHERE u2.modify_date IS NULL; </code></p> <p>Can somebody please help me with this?</p>
 

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