User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Oracle section within the Web Development category of DaniWeb, a massive community of 391,989 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,217 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Oracle advertiser:
Views: 1264 | Replies: 3
Reply
Join Date: May 2008
Posts: 33
Reputation: 2eXtreme is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
2eXtreme 2eXtreme is offline Offline
Light Poster

Select max date, then max time for that date?

  #1  
Jul 3rd, 2008
Hey guys

I have a table, that lists people, with a correpsonding date and time for each activity. My structure is like:

PersonID......Date............Time
872367.........01/01/08......15:00:00
872367.........01/01/08......16:00:00
872367.........01/01/08......18:00:00
976737.........01/01/08......19:00:00
976737.........02/01/08......16:00:00
911967.........03/01/08......18:00:00

I want to have a query that returns each persons latest activity date and time, so I want a table like:

PersonID......Date............Time
872367.........01/01/08......18:00:00
976737.........02/01/08......16:00:00
911967.........03/01/08......18:00:00

I tried something like

select PersonID, max(Date), max(Time)
from myTable
group by PersonID

This returned the

PersonID, latest activity date for that person, but not the latest time for that date, just the latest time for that person, if that makes sense?

So I got something like:

PersonID......Date............Time
872367.........01/01/08......18:00:00
976737.........02/01/08......19:00:00
911967.........03/01/08......18:00:00

Notice how the second row of data has the max date for that person, and the max time for that person - I need the max date for that person, and the max time for that date

Thanks for any help!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 406
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Pro in Training

Re: Select max date, then max time for that date?

  #2  
Jul 3rd, 2008
  1. SELECT ID, date, time FROM tbl
  2. WHERE date =(SELECT max(date) FROM tbl)
  3. AND time= (SELECT max(time) FROM tbl)
  4. GROUP BY ID

?
Reply With Quote  
Join Date: May 2008
Posts: 33
Reputation: 2eXtreme is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
2eXtreme 2eXtreme is offline Offline
Light Poster

Re: Select max date, then max time for that date?

  #3  
Jul 3rd, 2008
that wouldn't run, saying it wasnt a group by, so i added the date and time to the group by, and when i ran it, i didnt get any results back, just an empty result set

thanks for your time!
Reply With Quote  
Join Date: Dec 2004
Posts: 406
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Pro in Training

Re: Select max date, then max time for that date?

  #4  
Jul 6th, 2008
thowwy!!!! >_<

  1. SELECT id, date1, max(timee) FROM datetime
  2. GROUP BY id, date1


This should work ..

+_+
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Oracle Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Oracle Forum

All times are GMT -4. The time now is 9:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC