If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > help with limiting query results

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-04, 14:44
oizone oizone is offline
Registered User
 
Join Date: Jan 2004
Location: Finland
Posts: 1
help with limiting query results

Hi,

I have the following table in postgres:

hostname | username | logontime
----------+---------------+----------------------------
ws1 | rautaonn | 2004-01-13 21:25:01.100336
ws1 | administrator | 2004-01-13 21:25:07.706546
ws1 | testuser | 2004-01-13 21:25:16.084844
ws2 | testuser | 2004-01-13 21:25:18.683653
ws2 | testuser2 | 2004-01-13 21:25:20.862199
ws2 | administrator | 2004-01-13 21:25:25.932736
ws2 | oizone | 2004-01-13 21:25:30.107574



and I would need to create a query that selects each hostname only once with username that has the latest timestamp in the logontime column.
The real table has about 5000 rows with ¨500 different hostnames, and I would need this query for reporting. Any help would be appreciated.

Thank in advance.

-Onni Rautanen
Reply With Quote
  #2 (permalink)  
Old 01-14-04, 00:34
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
select t.*
from table t
where logontime = (select max(logontime) from table where id = t.id);
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On