473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 10726
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

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

Similar topics

3
by: jas | last post by:
> This is what I want to do with the data table below. > > I only want it to show one id for each issue. ( ie, 4001 only once, > 4002 only once, etc. But only the one with the latest date and...
2
by: John | last post by:
I have a query that returns this recordset: Bob, 1/1/2000 Bob, 3/1/2001 Bob, 2/4/2004 Bob, 5/9/2002 I need the query to return this instead: Bob, 2/4/2004 So, it needs to return the most...
3
by: Alec | last post by:
Hi All, I want to create a report listing all the people's birthdays that are in the current month, in other words, if I clicked to open the report today, it would show everyone who's birthday...
1
by: TGEAR | last post by:
I have a column which stores dates (datetime data type). I would like to fetch one data which is the most latest date among them. So if there are 04/01/06, 05/08/06, 05/12/06, 06/15/06, then...
8
by: TGEAR | last post by:
I have an ItemSTDPriceHistory table as below and this is a child table of itemlookup table with one to many relationship. if exists (select * from dbo.sysobjects where id = object_id(N'.') and...
6
by: piyushdabomb | last post by:
Hi All, Currently, I have a SQL query where I need to grab the SECOND latest date by group. COMPONENTID COMPLETIONDATE CBT_HAZCOM 02/26/2007 15:17:00 CBT_HAZCOM 07/31/2007 21:23:00 QS ...
8
by: helpmeplease213 | last post by:
Hello, I have a table that has five categories: Unit No, Date, P1, P2, P3. I have a query that only extracts data from the table that is over 40 for P1, P2 or P3 but I only want the data with...
2
by: selvialagar | last post by:
i have a date field in a table..i want to retrieve the data with latest date...is there any query for that.....
3
by: ghssal | last post by:
how i can select the latest order for a customer in oracle forms and save this order as a new order whith new date. i use GROUP BY customer_ID and MAX(order_date) but i get another customer_ID and...
2
by: rkferguson | last post by:
Hi Folks, I have a table that captures information about documents that leave the office. Some of those documents may get a signature and then return to the office. Need away to query the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.