|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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 martijn |
|
#2
|
|||
|
|||
|
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).] |
|
#3
|
|||
|
|||
|
Thanx, that's what i'm looking for.
Where can I find a manual/tutorial that goes futher than the standard manual? Martijn |
|
#4
|
|||
|
|||
|
I'm working with almost the same problem. How do you print the results to the screen using apache and php3.
Thanks in advance, Bob |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > SELECT DISTINCT question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|