yup, that was exactly it. Sorry about the simple question. I didn't realize that was what group by does.... Lewis
----- Original Message ----- From: "Roger Baklund" <[EMAIL PROTECTED]> To: "mysql" <[EMAIL PROTECTED]> Cc: "Lewis Watson" <[EMAIL PROTECTED]> Sent: Monday, February 17, 2003 5:02 AM Subject: Re: Need Distinct and Min... > * Lewis Watson > > I have a table with three fields. In the first field I have a range of > > numbers 1-20; all repeated more than once. In the third field I have a > > number ranging from 10000 to 200000 in each row. I need to choose the > > lowest amount in the third column for each distinct value in the fist > > column. Will someone help me out with this query? > > Maybe I am misinterpreting your question, because this seems like a standard > GROUP BY query.... creating some test data: > > use test; > create table lewis (f1 int,f2 int,f3 int); > insert into lewis values (1,0,10000); > insert into lewis values (1,0,10001); > insert into lewis values (2,0,10021); > insert into lewis values (2,0,10022); > insert into lewis values (3,0,10032); > insert into lewis values (3,0,10033); > > mysql> select * from lewis; > +------+------+-------+ > | f1 | f2 | f3 | > +------+------+-------+ > | 1 | 0 | 10000 | > | 1 | 0 | 10001 | > | 2 | 0 | 10021 | > | 2 | 0 | 10022 | > | 3 | 0 | 10032 | > | 3 | 0 | 10033 | > +------+------+-------+ > 6 rows in set (0.00 sec) > > mysql> select f1,min(f3) from lewis group by f1; > +------+---------+ > | f1 | min(f3) | > +------+---------+ > | 1 | 10000 | > | 2 | 10021 | > | 3 | 10032 | > +------+---------+ > 3 rows in set (0.09 sec) > > Is this what you wanted? > > Some related links: > > <URL: http://www.mysql.com/doc/en/example-Maximum-column-group.html > > <URL: http://www.mysql.com/doc/en/Group_by_functions.html > > <URL: http://www.mysql.com/doc/en/example-Maximum-column-group-row.html > > > -- > Roger > > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php