X-Original-To: pgsql-sql@postgresql.org Received: from beamish.nsd.ca (beamish.nsd.ca [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id 2255B475AFF for ; Fri, 14 Mar 2003 12:11:39 -0500 (EST) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id MAA30703; Fri, 14 Mar 2003 12:11:43 -0500 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma030695; Fri, 14 Mar 03 12:11:29 -0500 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id MAA01470; Fri, 14 Mar 2003 12:07:14 -0500 Message-ID: <3E720DBF.D71D2D75@nsd.ca> Date: Fri, 14 Mar 2003 12:13:35 -0500 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.18-24.7.x i686) X-Accept-Language: en MIME-Version: 1.0 To: "Sill-II, Stephen" Cc: pgsql-sql@postgresql.org Subject: Re: look for latest user login in one table from a list of users References: <4BAE87828F06EB45B2641B83D370350F4663@ostex002.ad.ost.dot.gov> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200303/367 X-Sequence-Number: 12406 Try: select users."User-Name", ss."Date", ss."Time" from users left outer join ( select distinct on ("User-Name") "User-Name", "Date", "Time" order by 1, 2 DESC, 3 DESC) as ss on ( users."User-Name" = ss."User-Name") order by 1; It help if yo uhave an index on logs( "User-Name", "Date" desc, "Time" desc). JL PS Can't you convert "Date" || "Time" to timestamp? "Sill-II, Stephen" wrote: > > I'm trying to come up with an efficient way to do the following task, but I > haven't found the correct join syntax to do it. > > I have table "users" for keeping a list of users I need to check logins for. > It contains the following fields: > > id,Full-Name,User-Name > > I have table called "logs" that contains the actual radius log data. The > three fields I am concerned with are: > > User-Name,Date,Time > > I have gotten thus far almost what I want with the following query. > > SELECT users."User-Name",max(logs."Date") as login_date,max(logs."Time") as > login_time FROM logs where logs."User-Name"=users."User-Name" GROUP BY > users."User-Name"; > > This gives me the User-Name, date, and time of people WHO HAVE LOGGED IN. > I'm looking to have a query that returns all of the users in the first > table, including those who have not logged in. I have an external perl > script that generates a nice html report for the manager. I have a script > that parses the raw .csv files, but I'm trying to move it entirely to > postgres, including if possible stored-procedures in plperl. I already have > a perl script that imports the raw log files into the logs table. > > Am I on the right track? > > Thanks, > > Stephen Sill II > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org