Thread: SQL Query Help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Question SQL Query Help


    Consider the scenario,

    Col 1 Col 2 Col3 ...
    A 1 100 ...
    A 1 100 ...
    A 3 100 ...
    B 4 101 ...
    B 4 101 ...
    B 4 101 ...

    I need to eliminate duplicates based on Col 1-3 and print other columns,
    Col 1 Col 2 Col3 ...
    A 1 100 ...
    A 3 100 ...
    B 4 101 ...

    Can this be acheived using a query?
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,279
    Rep Power
    4279
    Originally Posted by sriharsha_12
    I need to eliminate duplicates based on Col 1-3 and print other columns
    Code:
    SELECT col1
         , col2
         , col3
         , MAX(col4)
         , MIN(col5)
         , AVG(col6)
      FROM daTable
    GROUP
        BY col1
         , col2
         , col3
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0
    Thanx

IMN logo majestic logo threadwatch logo seochat tools logo