MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old February 17th, 2000, 12:34 PM
Martijn Martijn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Posts: 14 Martijn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old February 17th, 2000, 03:00 PM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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).]

Reply With Quote
  #3  
Old February 17th, 2000, 07:37 PM
Martijn Martijn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Posts: 14 Martijn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanx, that's what i'm looking for.

Where can I find a manual/tutorial that
goes futher than the standard manual?

Martijn

Reply With Quote
  #4  
Old March 24th, 2000, 03:01 PM
bbrown bbrown is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 24 bbrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > SELECT DISTINCT question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway