selecting from table where timestamp is latest

Christian Burgos

i have made a table for an audit trail.

CREATE TABLE IF NOT EXISTS `audit_trail_timer` (
  `_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `remaining_duration` varchar(50) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`_id`)
)

now i wanted to select a row where the timestamp is the most recent one.

$query = select * from audit_trail_timer where user_id='$id' and timestamp='';
Ezhil
   try this

   SELECT * FROM audit_trail_timer WHERE user_id='$id' 
    ORDER BY TIMESTAMP  DESC LIMIT 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

selecting the single largest/smallest/first/latest row from a table where dates/amounts are not unique

From Dev

mySQL - Selecting the latest row from a table

From Dev

Selecting Latest Row From MAX Row of 3rd Table

From Dev

Hive Data selecting latest value based on timestamp

From Dev

Selecting the file with latest timestamp using MORE command

From Dev

Getting the latest 'role-switch' timestamp from a messages table

From Dev

Selecting Data from Joomla SQL Table where any value is the variable

From Dev

SQL Selecting From One Table With Multiple Where Clauses

From Dev

Simple SQL query selecting from table where email = email

From Dev

MySQL - Selecting data from another table for a WHERE clause

From Dev

SQL Select latest result from table where keyword = and competitor =

From Dev

How to select from SQL table WHERE a TIMESTAMP is a specific Date

From Dev

Select from table where timestamp is within x seconds

From Dev

Selecting from table into a column

From Dev

Not selecting data from table

From Dev

Selecting information from table

From Dev

Selecting latest record from multiple joined tables

From Dev

SQL: Selecting all from a table, where related table, doesn't have a specified field value

From Dev

Selecting, Storing, Selecting from different table

From Dev

Selecting values from a table where values from one column is divided into multiple columns

From Dev

Selecting rows from one table where value and order from another in MYSQL

From Dev

Selecting records from a table and then selecting a count of records from another table

From Dev

Selecting data from two mysql tables where there may be nonexistent data in second table

From Dev

Selecting only rows from master table where subtable rows fulfill a condition

From Dev

Selecting from table where one column holds many data types as varchar

From Dev

Selecting all Records from Table where the Part Number matches list of Part Numbers in CSV file

From Dev

Selecting data from table where sum of values in a column equal to the value in another column

From Dev

Selecting dimension table from SSAS

From Dev

Ruby not selecting from the right table

Related Related

  1. 1

    selecting the single largest/smallest/first/latest row from a table where dates/amounts are not unique

  2. 2

    mySQL - Selecting the latest row from a table

  3. 3

    Selecting Latest Row From MAX Row of 3rd Table

  4. 4

    Hive Data selecting latest value based on timestamp

  5. 5

    Selecting the file with latest timestamp using MORE command

  6. 6

    Getting the latest 'role-switch' timestamp from a messages table

  7. 7

    Selecting Data from Joomla SQL Table where any value is the variable

  8. 8

    SQL Selecting From One Table With Multiple Where Clauses

  9. 9

    Simple SQL query selecting from table where email = email

  10. 10

    MySQL - Selecting data from another table for a WHERE clause

  11. 11

    SQL Select latest result from table where keyword = and competitor =

  12. 12

    How to select from SQL table WHERE a TIMESTAMP is a specific Date

  13. 13

    Select from table where timestamp is within x seconds

  14. 14

    Selecting from table into a column

  15. 15

    Not selecting data from table

  16. 16

    Selecting information from table

  17. 17

    Selecting latest record from multiple joined tables

  18. 18

    SQL: Selecting all from a table, where related table, doesn't have a specified field value

  19. 19

    Selecting, Storing, Selecting from different table

  20. 20

    Selecting values from a table where values from one column is divided into multiple columns

  21. 21

    Selecting rows from one table where value and order from another in MYSQL

  22. 22

    Selecting records from a table and then selecting a count of records from another table

  23. 23

    Selecting data from two mysql tables where there may be nonexistent data in second table

  24. 24

    Selecting only rows from master table where subtable rows fulfill a condition

  25. 25

    Selecting from table where one column holds many data types as varchar

  26. 26

    Selecting all Records from Table where the Part Number matches list of Part Numbers in CSV file

  27. 27

    Selecting data from table where sum of values in a column equal to the value in another column

  28. 28

    Selecting dimension table from SSAS

  29. 29

    Ruby not selecting from the right table

HotTag

Archive