Home Forums SQL Server 2005 T-SQL (SS2K5) how can i select distinct values from 1 column in my query RE: how can i select distinct values from 1 column in my query

  • mrichardson 57577 (6/13/2013)


    I would like to select distinct values from 1 column in my query.

    If I was selecting just 1 column in a simple query it would probably work, but I've got a more complex query and having trouble with it.

    here is my code:

    SELECT db.myTable.myFieldId, db.myFields.ModuleId, db.myTable.FieldValue

    FROM db.myTable INNER JOIN

    db.myFields ON db.myTable.myFieldId = db.myFields.myFieldId INNER JOIN

    db.myRows ON db.myTable.myRowId = db.myRows.myRowId

    WHERE (db.myFields.ModuleId = 1397) AND (db.myTable.myFieldId = 221)

    The part I want to be distinct is this bit: db.myTable.FieldValue

    If I insert the word 'distinct' before it, an error returns saying I can't do this.

    thanks,

    mark.

    If your base data was like this:

    (myFieldId, ModuleId, FieldValue)

    (1,2,1)

    (3,4,1)

    and you want 'FieldValue' to be distinct, which version of myFieldId and moduleId would you want to display?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.