Group by not working in union?

时间:2016-10-09 15:53:12

标签: php mysql

I have this code to group the item by brand in my first query i get the itemcode.
In the next query i get the brand of itemcode in first query and group it by brand but when i tried to group it its not working did i did wrong or something? thanks in advance

 $babawasan = mysqli_query ($link,"select  DISTINCT itemcode FROM  (
    (select ITEM_CODE_MX as itemcode,IMEI_MX as imei, BRANCH_CODE_MX as branch from inventory) UNION ALL
    (select ITEM_CODE_MX as itemcode,IMEI_MX as imei, SITE_TO_MX as branch from transferinventory where STATUS_MX='RECEIVED')UNION ALL
    (select ITEM_CODE_MX as itemcode,IMEI_MX AS imei,SHIP_TO_MX AS branch from purchaseorder where COMPLETION_STATUS_MX='COMPLETE' )UNION ALL
    (select INVOICE_ITEM_CODE_MX as itemcode,INVOICE_ITEM_SERIAL_MX as imei,BRANCH_CODE_MX as branch from invoice where INVOICE_STATUS_MX='VOID' or INVOICE_STATUS_MX='PROCESSING'))
    UnionResult where branch='".$display_branchcode."' ") ;

while($babawasanrow=mysqli_fetch_array($babawasan)){
    $itemcode = $babawasanrow["itemcode"];

    $item     = mysqli_query($link,"select * from item where ITEM_CODE_MX='".$itemcode."' GROUP BY ITEM_BRAND_MX");

    while($row2=mysqli_fetch_array($item)) {
        echo        $brand=$row2["ITEM_BRAND_MX"];
        echo '<br>';
    }
}

0 个答案:

没有答案