February 17th, 2000, 01:34 PM
How do I retrieve 2 or more columns
from a table with the distinct syntax
I mean something like this:
SELECT pet, name, owner DISTINCT owner FROM pet
February 17th, 2000, 04:00 PM
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
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
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)
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).]
February 17th, 2000, 08:37 PM
Thanx, that's what i'm looking for.
Where can I find a manual/tutorial that
goes futher than the standard manual?
March 24th, 2000, 04:01 PM
I'm working with almost the same problem. How do you print the results to the screen using apache and php3.
Thanks in advance,