Solved

SQL Query Help

Posted on 2014-02-18
2
200 Views
Last Modified: 2014-02-18
Hello there,

I have this sql query which is working as I expect but it is also get this null values for each product. How can I exclude those null qtyArrived and BatchNo

SELECT
        supplierOrderDetails.productID as productid,
        supplierOrder.id as supplierorderid,
        product.brandname as brandname,
        product.productcode as code,
        supplierOrderDetails.orderQty as orderQty,
        supplierOrderDetails.id as sodID,
        SUM(supplierOrderReceiveDetail.qtyArrived) as qtyArrived ,
        supplierOrderReceiveDetail.batchNo as BatchNo
    FROM
        supplierOrder  
    LEFT OUTER JOIN
        supplierOrderDetails  
            ON      (
                supplierOrderDetails.supplierOrderID = supplierOrder.ID
            )  
    LEFT OUTER JOIN
        product  
            ON  (
                product.id = supplierOrderDetails.productID
            )  
    LEFT OUTER JOIN
        supplierOrderReceive  
            ON         (
                supplierOrderReceive.supplierOrderID = supplierOrder.ID
            )  
    LEFT OUTER JOIN
        supplierOrderReceiveDetail  
            ON         (
                supplierOrderReceiveDetail.supplierOrderReceiveID = supplierOrderReceive.ID
            )           
            AND   (
                supplierOrderReceiveDetail.ProductID =supplierOrderDetails.ProductID
            )       
    WHERE
        supplierOrder.ID = 1  and supplierOrderDetails.isComplete  = 1
        GROUP BY
        supplierOrderDetails.productID,
        supplierOrderDetails.orderQty,
        product.brandname,
        product.productcode,
        supplierOrder.id,
        supplierOrderDetails.id,
        supplierOrderReceiveDetail.batchNo

Open in new window

2-18-2014-1-06-15-PM.gif
0
Comment
Question by:zolf
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39866865
change:
LEFT OUTER JOIN         supplierOrderReceiveDetail  

into
INNER JOIN         supplierOrderReceiveDetail  

to avoid non-matched rows.
however, if the columns are indeed null in that table, you need to add  this after the GROUP BY conditions:

HAVING SUM(supplierOrderReceiveDetail.qtyArrived) is not null
0
 

Author Closing Comment

by:zolf
ID: 39866967
cheers !!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now