Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get the latest record of my tabel

Tags:

mysql

How can i get the latest date out of a tabel. Perhaps it is better if i show you what i mean.

This is my current tabel output

TransactionID          Title           Date
23132                  Locaton         2013-05-17 10:02:04
23131                  Novuel          2013-05-16 16:26:45
23130                  Novuel          2013-05-16 11:41:21
23129                  Locaton         2013-05-15 15:02:47
23128                  Mama Rosa       2013-05-15 14:42:44
23127                  Locaton         2013-05-14 18:21:32
23126                  Rohan           2013-05-14 12:46:56

And this is the desired output:

TransactionID          Title           Date
23132                  Locaton         2013-05-17 10:02:04
23131                  Novuel          2013-05-16 16:26:45
23128                  Mama Rosa       2013-05-15 14:42:44
23126                  Rohan           2013-05-14 12:46:56

As you can se i only want the latest date from each title out of mysql.

And this is how i tried so far to get the desired output:

    ("SELECT t.transactionid,
       ct.title,
       max(t.transactiontime)
FROM exp_channel_titles AS ct
LEFT JOIN transactions AS t ON (ct.entry_id = t.restaurant_id)
WHERE t.transactiontime IN
    (SELECT max(t.transactiontime)
     FROM transactions AS t)
GROUP BY ct.entry_id
ORDER BY t.transactiontime DESC");
like image 302
Zaz Avatar asked Nov 28 '25 03:11

Zaz


1 Answers

select * from t t1
where 
NOT EXISTS (select transactionID 
                from t where t.Title=t1.title
                         and t.date>t1.date)

SQLFiddle demo

like image 143
valex Avatar answered Nov 30 '25 18:11

valex