Results 1 to 4 of 4

Thread: SQL statement?

  1. #1

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179

    Cool

    Hi
    What SQL statement should i write if i want to select a data from a column that has duplicate data?

    Any help or suggestion will be greatly appreciated

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Location
    A caravan park in the Midlands (UK)
    Posts
    101

    Question

    I assume you only want the single occurence of the duplicates? just use DISTINCT. ie if you've a 'firstname' column (where you'll probably get multiple 'Steve's and 'Sarah's) you'd do:
    Code:
    SELECT DISTINCT forename FROM names ORDER by forename
    Anakim

    It's a small world but I wouldn't like to paint it.

  3. #3

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    Thanks for the reply ANAKIM
    But what should i do if that column contain duplicate numbers ?

  4. #4
    Lively Member
    Join Date
    Jun 2000
    Location
    A caravan park in the Midlands (UK)
    Posts
    101

    Smile

    Exactly the same! It matters not a jot what the column contains. Distinct can be used for multiple columns, say if you were looking for all the different results in an exam, if the table contained names and sexes of the entrants as well as the mark....

    Code:
    SELECT DISTINCT score FROM entrants
    would get all the different scores while...
    Code:
    SELECT DISTINCT score, sex FROM entrants
    would get all the different scores for male, female and in-betweens.
    Anakim

    It's a small world but I wouldn't like to paint it.

Posting Permissions

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



Click Here to Expand Forum to Full Width