SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Norway - Oslo
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Making sure i get unique row.

    Ok.

    Could be the subject was really bad, but not sure how to explain it shortly, dont have a word for it.

    Consider the following table:

    id | something | anotherthing

    Lets say this table consists of 3 rows:

    1 | 1000 | 123
    2 | 1001 | 125
    3 | 1001 | 330

    Id like to do a query to get all entries, except, i dont want more than 1 result where there are rows which have the post "something" identical.

    So from that table id like to get row 1 and 2 returned.

    I cant think how to do this, are there a command i can easily use to achieve this?

    Thanks in advance.

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT DISTINCT
    something
    FROM
    table...
    Lats...

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Norway - Oslo
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for quick reply

  4. #4
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It won't work. It will return the distinct values of the attribute "something", but not the rows containing the value "something". Or are you really just after the distinct values of "something"

  5. #5
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good point DJ
    Code:
    SELECT DISTINCT
    something, anotherthing
    FROM
    table...
    Lats...

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    findus, if there is more than one row that has the same value of something, which row do you want to keep? the one with the lowest id? the one with the lowest anotherthing?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •