Select rows with same id but different value in another column

后端 未结 8 1604
名媛妹妹
名媛妹妹 2020-12-08 01:50

I tried for hours and read many posts but I still can\'t figure out how to handle this request:

I have a table like this:

+------+------+
|ARIDNR|LIE         


        
8条回答
  •  攒了一身酷
    2020-12-08 02:45

    Join the same table back to itself. Use an inner join so that rows that don't match are discarded. In the joined set, there will be rows that have a matching ARIDNR in another row in the table with a different LIEFNR. Allow those ARIDNR to appear in the final set.

    SELECT * FROM YourTable WHERE ARIDNR IN (
        SELECT a.ARIDNR FROM YourTable a
        JOIN YourTable b on b.ARIDNR = a.ARIDNR AND b.LIEFNR <> a.LIEFNR
    )
    

提交回复
热议问题