SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting unique rows

    I want to get all of the rows, but I only want one per `ip`.

    Basically, I have a field called `ip`, I want to select all of the rows, except I only want one per `ip`. Is this possible with a simple query or do I need to loop through them all?
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  2. #2
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Meh, yet again I figured it out before anyone else.


    I think I need a stupid friend to just IM when I can't figure it out so I can figure it out right away.

    The way was to use SELECT DISTINCT `ip` FROM ...
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  3. #3
    Non-Member
    Join Date
    Nov 2003
    Location
    here
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does that select a row at random?

  4. #4
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cristiano
    Does that select a row at random?
    No - it just selects distinct rows, if there are two IP's which are the same it will only apear once in the results - nothing to do with random.

  5. #5
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DISTINCT eliminates all duplicate occurences of whatever field you specify as you want as distinct.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •