Results 1 to 2 of 2

Thread: Really difficult- can you help?

  1. #1
    Join Date
    Jul 2007
    Location
    England
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Really difficult- can you help?

    I have a field in my database with values that INCREASE (they never decrease). I need to find a way of selecting the NON-DUPLICATE rows.

    Code:
    NUM
    
    1
    2
    2
    3
    4
    4
    4
    4
    5
    5
    6
    7
    8
    8
    IMPORTANT

    The DISTINCT keyword is no use to me. By using the distinct keyword for the example above I'd be left with only the values that occur once. But I also want ONE OF EACH of the duplicated rows to be left as well.

    So the example above would become:

    Code:
    NUM
    
    1
    2
    3
    4
    5
    6
    7
    8
    This is because the values that occur only once are selected (this is what DISTINCT does) but then the values that occur multiple times are selected only ONCE.

    I'm sorry if I sound like I've over-explained this, but I've had trouble trying to tell people what I need- people keep recommending the DISTINCT keyword.

    Thanks in advance- I hope you can help.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't know of a way to do this in mysql. The basic method I can think of is using the number as some sort of index, then if you add it again it will replace it. This is easily done in PHP, using a number of methods. For example, you could use them in an array:
    loop through each result with:
    $array[$number] = [whatever];
    Then you could store it that way. Or if you just want the numbers, you could store them as the values of the array and just not copy it if it already exists. Or use one of the sort functions that only returns unique values.

    As for mysql, the only idea that I have is to simulate creating a new table (there's some method I've heard of, but can't remember how), then copy values like in the php array-- overwriting those that are not unique.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    MrRSMan (12-29-2009)

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
  •