Select rows with a duplicate ID but different value in another column



  • I have a table like this

    enter image description here

    I would like to select the Itemid that occurs more than once with a different Rate with group by Masterid

    The output should be something like:

    enter image description here



  • select tlt.* from table_like_this tlt
      where exists (select masterid, itemid from (
         select distinct masterid, itemid, rate from table_like_this) tlt2
         where tlt2.masterid = tlt.masterid
           and tlt2.itemid   = tlt.itemid
         group by masterid, itemid
         having count(*) > 1);
    

    See https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=e09c6647c4c5c04a8013125e83090ec6

    PS. images of data are completely useless. Were you too lazy to read how to ask for assistance?


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2