#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    14
    Rep 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    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).]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    14
    Rep 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
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    24
    Rep 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

Similar Threads

  1. Database select question
    By Lobos34 in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 06:49 PM
  2. select distinct problem
    By soupman99 in forum PHP Development
    Replies: 2
    Last Post: December 7th, 2003, 08:40 PM
  3. select distinct problem
    By soupman99 in forum PHP Development
    Replies: 1
    Last Post: December 7th, 2003, 03:20 PM
  4. Is SELECT DISTINCT what I need to use?
    By jbelew in forum MySQL Help
    Replies: 1
    Last Post: April 3rd, 2003, 02:20 PM
  5. mysql select question
    By MRK in forum PHP Development
    Replies: 1
    Last Post: August 28th, 2001, 11:00 PM

IMN logo majestic logo threadwatch logo seochat tools logo