Solved

SQL help - Remove Null from Group By

Posted on 2014-01-07
4
489 Views
Last Modified: 2014-01-08
Hello there,

I have this query which is working but when I do Group By it is also gets the null batchno. how can I not get those nukk batch no. see attached file to see what is happening.

cheers
Zolf

this is my query

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,
        supplierOrderReceiveDetail.expDate
    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      
    GROUP BY
        supplierOrderDetails.productID,
        supplierOrderDetails.orderQty,
        product.brandname,
        product.productcode,
        supplierOrder.id,
        supplierOrderDetails.id,
        supplierOrderReceiveDetail.batchNo,
        supplierOrderReceiveDetail.expDate

Open in new window

1-8-2014-9-14-02-AM.gif
0
Comment
Question by:zolf
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 39764341
Hi,
add the following where caluse

WHERE
        supplierOrder.ID = 1  and  supplierOrderReceiveDetail.batchNo is not null

-FA
0
 

Author Comment

by:zolf
ID: 39764351
by the way can you tell me why I get that BatchNo null even when I don't have any batch no col as null in that table
0
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 500 total points
ID: 39764370
because you use outter join verb.

Change

LEFT OUTER JOIN
        supplierOrderReceiveDetail

to

INNER JOIN
        supplierOrderReceiveDetail


See
stackoverflow.com/questions/38549/difference-between-inner-and-outer-join
fro more info.

-FA
0
 

Author Closing Comment

by:zolf
ID: 39764383
thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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

12 Experts available now in Live!

Get 1:1 Help Now