Select rows with same id but different value in another column

后端 未结 8 1598
名媛妹妹
名媛妹妹 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:43
    $sql="SELECT * FROM TABLE_NAME WHERE item_id=".$item_id;
    
    $query=mysql_query($sql);
    
    while($myrow=mysql_fetch_array($query)) {
    
    echo   print_r($myrow,1);
    
    
    }
    
    0 讨论(0)
  • 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
    )
    
    0 讨论(0)
提交回复
热议问题