how do i get last result in group by MySQL query (not the first)

Rodrick Bouchard

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

manivannan

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mysql Query Group by Last record and first record

From Dev

How do I find the average of the result of a group by SQL query?

From Dev

How do I get last record from a mysql column through php where several other query is running

From Dev

How do I use more "select query" with Mysql to get result from different table

From Dev

How do I create MySQL query to get result from different year?

From Dev

How to get the last inserted row when I Group by column in mySQL?

From Dev

How do I order the elements in a group by linq query, and pick the first?

From Dev

How do I use dateadd to get the first day of last year?

From Dev

How do I get the buttons to stop at first and last image

From Dev

MySQL Query - How do I get a SUM with GROUP BY and WHERE condition and use LEFT OUTER JOIN?

From Dev

How do I put a previous result into the next query? MYSQL

From Dev

Php/MYSQl to output first and last result of query foreach value of an array?

From Dev

How do I get the first group of alpha characters from string?

From Dev

MySQL How to Group While Sorting Query Result?

From Dev

How do I pull the first result from each unique result of an SQL query?

From Dev

How do I get the count for a SQL query containing a GROUP BY statement?

From Java

How do I group the first four columns and the last four columns using Dplyr?

From Dev

How to get last first and last from table with same date (query)?

From Dev

How do I print the first and last value?

From Dev

MYSQL Query to get the SUM and LAST record value in Group BY

From Dev

MySQL get name of last added value on group by query

From Dev

CodeIgniter: How do I correctly run two queries with each other based on the first query result?

From Dev

MySQL Join Query { How to get following Result }

From Dev

how to get the result of a mysql prepared query

From Dev

How to write a query to get result in mysql

From Dev

how to get mysql query result in jsp page?

From Dev

SSRS Chart Group Series - How do I get the secondary series group to start at the first data point?

From Dev

How do I get the last known location for the first time I execute a service?

From Dev

How do I query same table of several databases with same structure and get all the query result together?

Related Related

  1. 1

    Mysql Query Group by Last record and first record

  2. 2

    How do I find the average of the result of a group by SQL query?

  3. 3

    How do I get last record from a mysql column through php where several other query is running

  4. 4

    How do I use more "select query" with Mysql to get result from different table

  5. 5

    How do I create MySQL query to get result from different year?

  6. 6

    How to get the last inserted row when I Group by column in mySQL?

  7. 7

    How do I order the elements in a group by linq query, and pick the first?

  8. 8

    How do I use dateadd to get the first day of last year?

  9. 9

    How do I get the buttons to stop at first and last image

  10. 10

    MySQL Query - How do I get a SUM with GROUP BY and WHERE condition and use LEFT OUTER JOIN?

  11. 11

    How do I put a previous result into the next query? MYSQL

  12. 12

    Php/MYSQl to output first and last result of query foreach value of an array?

  13. 13

    How do I get the first group of alpha characters from string?

  14. 14

    MySQL How to Group While Sorting Query Result?

  15. 15

    How do I pull the first result from each unique result of an SQL query?

  16. 16

    How do I get the count for a SQL query containing a GROUP BY statement?

  17. 17

    How do I group the first four columns and the last four columns using Dplyr?

  18. 18

    How to get last first and last from table with same date (query)?

  19. 19

    How do I print the first and last value?

  20. 20

    MYSQL Query to get the SUM and LAST record value in Group BY

  21. 21

    MySQL get name of last added value on group by query

  22. 22

    CodeIgniter: How do I correctly run two queries with each other based on the first query result?

  23. 23

    MySQL Join Query { How to get following Result }

  24. 24

    how to get the result of a mysql prepared query

  25. 25

    How to write a query to get result in mysql

  26. 26

    how to get mysql query result in jsp page?

  27. 27

    SSRS Chart Group Series - How do I get the secondary series group to start at the first data point?

  28. 28

    How do I get the last known location for the first time I execute a service?

  29. 29

    How do I query same table of several databases with same structure and get all the query result together?

HotTag

Archive