Results 1 to 2 of 2

Thread: Sql Query

  1. #1
    Join Date
    Feb 2004
    Location
    El Salvador
    Posts
    46

    Unanswered: Sql Query

    I have a table with the following info:

    col1, col2, col3
    name1a, name1b, 1
    name1a, name1b, 2
    name2a, name2b, 1
    name3a, name3b, 1
    name3a, name3b, 2

    how can I make a query so that I only get the rows that have the same col1, the same col2, but a diferent col3. Example:

    name1a, name1b, 1
    name1a, name1b, 2
    name3a, name3b, 1
    name3a, name3b, 2

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    select distinct t1.col1, t1.col2, t1.col3 from table t1
    inner join (select col1, col2, cnt = count(*)
    from table group by col1, col2 having count(*) > 1) t2
    on t1.col1 = t2.col1 and t1.col2 = t2.col2
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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