Need to query flat file, having trouble with self joins

  • I'm having some problems trying to query a table that is set up like so:

    NIGO
    IDINTERNALIDEVENT_DATEOTHER COLUMNS...
    13636361/20/2004...
    28989891/21/2004...
    33636361/26/2004...
    48989891/22/2004...
    53636361/31/2004...
    68989891/29/2004...

    The ID column is an Identity field. InternalID relates a group of records. The other column is there just as a place holder. There are actually 7 additional fields to the table, but are not relevant to the solution.

    One thing I need to do is to find the first record for each group of internalid, including all the other fields. The only way to be certain is to find the min(event_date) on internalid. This can be done with:

    select internalid, min(event_date) as event_date from nigo group by internalid

    However i'm not sure how to incorporate that into the rest of the solution. Somehow I need to get the unique ID for each of those records, and then join that to the full table.

  • select * from nigo a,

     (select internalid, min(event_date) as event_date from nigo group by internalid) b

     where a.internalid = b.internalid and a.event_date = b.event_date

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply