Re: Selecting rows from a distinct selection of one field
From: Adam Smith (private_at_hotmail.com)
Date: 12/09/04
- Next message: Jacco Schalkwijk: "Re: sp_detach_db from VB6 code failure"
- Previous message: Jo Segers: "Re: Performance of an INSERT with or without error handling"
- In reply to: Jacco Schalkwijk: "Re: Selecting rows from a distinct selection of one field"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 9 Dec 2004 14:10:26 -0000
Worked like a charm. It had a couple of dupes due to the time being only to
the second, but these are easy enough to erase.
pop by some time, I'll buy you a pint :D
Adam Smith
"Jacco Schalkwijk" <jacco.please.reply@to.newsgroups.mvps.org.invalid> wrote
in message news:u0AISle3EHA.536@TK2MSFTNGP10.phx.gbl...
> You can get the first row for each IP with:
> SELECT <column list>
> FROM log_table t1
> WHERE NOT EXISTS(SELECT NULL FROM log_table t2
> WHERE t1.IP = t2.IP AND (t2.date > t1.date OR (t2.date = t1.date AND
> t2.time > t1.time))
>
> This should perform reasonably well if you have an index on (IP, date,
> time)
>
> I see btw that we are almost neighbours ;-)
>
> --
> Jacco Schalkwijk
> SQL Server MVP
>
>
> "Adam Smith" <private@hotmail.com> wrote in message
> news:ehDM0bd3EHA.2804@TK2MSFTNGP15.phx.gbl...
>> I'm not that new to SQL, but still I can't figure this out.
>> I'm writing some routines to check through IIS logs.
>> After batch importing the logs I end up with 16 fields. Field 2 is the
>> IP addresses of our users. I can distinct this field and get all IPs
>> that access our website.
>>
>> What I then want to do, is using this list of ip's pull out 1 sample row
>> for each IP.
>> How do I go about doing this in pure sql (if I'd done it in ado I'd be
>> done by now).
>> Idealy I'm looking for a fast hitting sql query, as you can imagine the
>> logs can be quite large at times.
>>
>> Thanks in advance
>>
>> --
>> Regards,
>> Adam Smith
>> Assistant Computer Technician
>> Phone: +44 (0)20-8251-1332
>> E-mail: adam@101cd.com
>>
>> 101cd.com
>> 11 Keeley Road
>> Croydon
>> CR0 1TF
>>
>
>
- Next message: Jacco Schalkwijk: "Re: sp_detach_db from VB6 code failure"
- Previous message: Jo Segers: "Re: Performance of an INSERT with or without error handling"
- In reply to: Jacco Schalkwijk: "Re: Selecting rows from a distinct selection of one field"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|