I have the following table:
+--+-------------------+---------------------+-----------------------+ |ID| lt_user | lt_time_stamp | lt_activity_operation | +--+-------------------+---------------------+-----------------------+ |1 | External Sales | 2013-02-15 15:17:34 | login | |2 | External Sales | 2013-03-20 16:25:09 | login | |3 | Internal Sales | 2013-07-29 13:09:22 | login | |4 | Internal Sales | 2013-08-01 11:06:11 | login | |5 | Internal sales | 2013-08-02 10:06:59 | login | |6 | internal sales | 2013-08-02 10:21:38 | login | |7 | internal sales | 2013-08-07 16:13:01 | login | |8 | Internal Sales | 2013-08-12 10:51:16 | login | +--+-------------------+---------------------+-----------------------+
I'm trying to retrieve the last instance (Time stamp) of each user once.
What i need is:
+--+-------------------+---------------------+-----------------------+ |ID| lt_user | lt_time_stamp | lt_activity_operation | +--+-------------------+---------------------+-----------------------+ |2 | External Sales | 2013-03-20 16:25:09 | login | |8 | Internal Sales | 2013-08-12 10:51:16 | login | +--+-------------------+---------------------+-----------------------+
What I'm getting is:
+--+-------------------+---------------------+-----------------------+ |ID| lt_user | lt_time_stamp | lt_activity_operation | +--+-------------------+---------------------+-----------------------+ |3 | Internal Sales | 2013-07-29 13:09:22 | login | |1 | External Sales | 2013-02-15 15:17:34 | login | +--+-------------------+---------------------+-----------------------+
My Query is:
SELECT lt_user, lt_time_stamp, lt_activity_operation
FROM log_table
GROUP BY lt_user
ORDER BY lt_time_stamp DESC;
Thanks
Use Like this
SELECT lt_user, MAX(lt_time_stamp), lt_activity_operation FROM log_table GROUP BY lt_user, lt_activity_operation ORDER BY lt_time_stamp DESC;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments