I have a problem with an SQL query I'm trying to use. It's supposed to return all the fields of the set of records where TRIPNUM is unique. i.e. if I have the following table:
and what I want from the query is:
I want only one instance of the Blackpool trip (the others turn up because the database hasn't been terribly well designed and there's a bunch of fields which should really be in a separate table buggering things up).
If I use DISTINCT, I only get the TRIPNUM data, unfortunately this is no use because I need the entire record.
Is there a way to do what I want with SQL? I'm guessing there must be because it doesn't seem to be a particularly stupid thing to want to do. I just want to take the first instance of every unique TRIPNUM and ignore the rest, generating a recordset that just contains records with unique TRIPNUMs.
Somebody please help. I'm getting ready to throw things.![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Code:
ID TRIPNUM TRIPNAME
1 BS0207 Blackpool
2 BS0204 Alton Towers
3 BS0207 Blackpool
Code:
ID TRIPNUM TRIPNAME
1 BS0207 Blackpool
2 BS0204 Alton Towers
If I use DISTINCT, I only get the TRIPNUM data, unfortunately this is no use because I need the entire record.
Is there a way to do what I want with SQL? I'm guessing there must be because it doesn't seem to be a particularly stupid thing to want to do. I just want to take the first instance of every unique TRIPNUM and ignore the rest, generating a recordset that just contains records with unique TRIPNUMs.
Somebody please help. I'm getting ready to throw things.