468,541 Members | 1,758 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,541 developers. It's quick & easy.

select records by latest date

how can i get records by the latest date. ie. select last inserted records. mysql db structure below

Expand|Select|Wrap|Line Numbers
  1. timestamp  method  id comment
  2. 2009-01-10 getThud 16 "....."
  3. 2009-01-10 getFoo  12 "....."
  4. 2009-01-10 getBar  12 "....."
  5. 2009-01-11 getFoo  12 "....."
  6. 2009-01-11 getBar  12 "....."
desired results

Expand|Select|Wrap|Line Numbers
  1. timestamp  method  id comment
  2. 2009-01-10 getThud 16 "....."
  3. 2009-01-11 getFoo  12 "....."
  4. 2009-01-11 getBar  12 "....."
I used below code, iam not sure whether it's the right approach.

Expand|Select|Wrap|Line Numbers
  1. select max(timestamp),method,id from tables where 1 group by method,id order by timestamp desc 
May 4 '12 #1
1 9605
wooooooooow, i tried this, it's working

Expand|Select|Wrap|Line Numbers
  1. SELECT a.`timestamp`,a.`method`,a.`id`,d.`studentname`
  2. FROM `schools` a
  3. INNER JOIN `schoolstudent` d ON a.`studentid`=d.`studentid`
  4. WHERE a.`pid` IN (
  5.     SELECT MAX(`pid`)
  6.     FROM `schools`
  7.     GROUP BY `method`,`id`,`order`
  8. ORDER BY a.`id` ASC;
  9.  
May 4 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by TGEAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.