X-Original-To: pgsql-sql@postgresql.org Received: from dotmail001.DIR.DOT.GOV (dotmail001.ost.dot.gov [152.119.92.100]) by postgresql.org (Postfix) with SMTP id CC4F7474E44 for ; Fri, 14 Mar 2003 12:15:34 -0500 (EST) Received: from 152.119.92.39 by dotmail001.DIR.DOT.GOV (InterScan E-Mail VirusWall NT); Fri, 14 Mar 2003 12:15:33 -0500 Received: by ostex001.ad.ost.dot.gov with Internet Mail Service (5.5.2656.59) id ; Fri, 14 Mar 2003 12:15:31 -0500 Message-ID: <4BAE87828F06EB45B2641B83D370350F4665@ostex002.ad.ost.dot.gov> From: "Sill-II, Stephen" To: 'Achilleus Mantzios' Cc: "'pgsql-sql@postgresql.org'" Subject: Re: look for latest user login in one table from a list of Date: Fri, 14 Mar 2003 12:15:24 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: text/plain; charset="iso-8859-1" X-Archive-Number: 200303/368 X-Sequence-Number: 12407 Thanks VERY VERY VERY much, After the following modifications, it works exactly as I need. SELECT users."User-Name",someq.login_date,someq.login_time FROM users LEFT OUTER JOIN (SELECT "User-Name",max("Date") AS login_date,max("Time") AS login_time FROM logs GROUP BY "User-Name") AS someq USING("User-Name"); THANKS! -----Original Message----- From: Achilleus Mantzios [mailto:achill@matrix.gatewaynet.com] Sent: Friday, March 14, 2003 4:15 PM To: Sill-II, Stephen Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] look for latest user login in one table from a list of users in a nother On Fri, 14 Mar 2003, 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"; Try foo=# SELECT users.name,someq.mlast from users left outer join (select id,max(last) as mlast from log group by id) as someq using(id); substituting with your names. > > 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 > -- ================================================================== Achilleus Mantzios S/W Engineer IT dept Dynacom Tankers Mngmt Nikis 4, Glyfada Athens 16610 Greece tel: +30-210-8981112 fax: +30-210-8981877 email: achill@matrix.gatewaynet.com mantzios@softlab.ece.ntua.gr