
February 17th, 2000, 03:00 PM
|
|
Contributing User
|
|
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Chances are you're going to have trouble unless you have a GROUP BY clause which is essential when you mix an aggregate function, i.e. min(), max(), count(), distinct() with a non-aggregate column.
Maybe this will help...
select distinct(owner), pet
from pet
group by pet; // this returns each type of pet once (bird, fish, frog) and the name of AN owner, in no particular order, kind of counter-intuitive based on the syntax, isn't it?
select distinct(pet), owner
from pet
group by owner; // this returns each owner name once (Bill, Fred, Sarah) and the type of pet that they own (bird, fish, frog), in no particular order
select owner, count(pet)
from pet
group by owner; // this returns each owner name and the number of pets each of them owns
The general rule is: However many non-aggregate columns you have in your SELECT clause, you must have those same columns listed in your GROUP BY clause
[This message has been edited by Kyuzo (edited February 17, 2000).]
|