|  | Posted by jim on 01/19/07 18:32 
You're right!
 And, I meant to say "unique combination of values from the first two
 columns" and "lowest value from the third column".
 
 select c1, c2, min(c3)
 from t1
 group by c1, c2
 
 It worked.. thanks!! :)
 
 I appreciate all the replies.
 
 I suspected my original post for help might have been vague...and it's
 the reason I included the example to help convey what I really meant.
 
 Do you have a great book to recommend that would have discussed this
 topic in detail (patterns book... and would have included examples,
 etc.)?    I'm also interested in reading about SQL optimizations (what
 to look for and how to address).
 
 Thanks again.
 
 
 Ed Murphy wrote:
 > jim wrote:
 >
 > > I've been searching and trying out SQL statements for hours and I'm
 > > still having a problem.
 > >
 > > I'm querying 3 tables... and I only want the first unique record
 > > returned.
 >
 > You need to clearly define "unique" and "first".  Based on your
 > example, it looks like you mean "unique combination of values from
 > the first two columns" and "lowest value from the third column".
 >
 > > Currently, the data returned looks like this..............
 > >
 > > New York      New York   A
 > > New York      New York   B
 > > New York      New York   C
 > > Los Angeles  California    A
 > > Los Angeles  California    B
 > > Los Angeles  California    C
 > >
 > >
 > > I want the select statement to return this instead...
 > >
 > > New York      New York   A
 > > Los Angeles  California    A
 >
 > select c1, c2, min(c3)
 > from t1
 > group by c1, c2
 >
 > You'll need to adjust this to account for three tables instead of
 > one, but hopefully you get the idea.
  Navigation: [Reply to this message] |