SQL Query - distinct with 2 values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SanjayP
    New Member
    • Mar 2007
    • 2

    SQL Query - distinct with 2 values

    I have a table defined as Table1 with rows below

    Index Name Value
    1 A 1.0 x
    1 A 2.0 x
    1 A 3.0 x

    1 B 1.0
    1 B 2.0
    1 B 3.0

    2 A 4.0 x
    2 A 5.0 x
    2 A 6.0 x

    The output required is marked with x.
    I need the output as all rows having the same names in a distinct index. If same index with a different name then ignore. Can anyone help with a simple-to-understand query.

    Thanks
    SanjayP
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Originally posted by SanjayP
    I have a table defined as Table1 with rows below

    Index Name Value
    1 A 1.0 x
    1 A 2.0 x
    1 A 3.0 x

    1 B 1.0
    1 B 2.0
    1 B 3.0

    2 A 4.0 x
    2 A 5.0 x
    2 A 6.0 x

    The output required is marked with x.
    I need the output as all rows having the same names in a distinct index. If same index with a different name then ignore. Can anyone help with a simple-to-understand query.

    Thanks
    SanjayP
    Try this:

    [PHP]SELECT * FROM Table1 WHERE Name = 'A'[/PHP]

    Comment

    • SanjayP
      New Member
      • Mar 2007
      • 2

      #3
      Thanks for trying.
      But its not what I am looking for.. though its correct for my example below its not correct for the whole data I have.

      Let me re-define the data rows for a better view
      Index Name Value
      1 A 1.0 x
      1 A 2.0 x

      1 B 1.0
      1 B 2.0

      2 A 4.0 x
      2 A 5.0 x

      3 B 6.0 x
      3 B 7.0 x

      3 C 6.0
      3 C 7.0

      Whatever is the first pair of index and name. I need all rows for that along with the values. (so with a 'group by' I may get the pairs but I lose the values)
      I need the rows marked with x.

      Comment

      • iburyak
        Recognized Expert Top Contributor
        • Nov 2006
        • 1016

        #4
        Try this:
        [PHP]
        SELECT Min(Index), Min(Name), Value
        FROM Table1
        GROUP BY Value[/PHP]

        Comment

        Working...