title: SQL VB6 - Showing all Entries in Datagrid while using UNION ALL and Left Join
body: <pre><code>create table TBLGRN (Supplier varchar(100),
                       ProductID INT,
                       QTY Int,
                       VoucherNo long);
  
  Create table TBLINV (CustomerName varchar(100),
                       ProductID Int,
                       Qty int,
                       Invoiceno Long);
  
  insert into tblgrn 
  (Supplier,ProductID,Qty,VoucherNo)
  Values
  ('Supplier1','1','5','12345');
  
  insert into tblgrn 
  (Supplier,ProductID,Qty,VoucherNo)
  Values
  ('Supplier1','2','3',NULL);
  
  insert into tblinv
  (CustomerName,ProductID,QTY,Invoiceno)
  values
  ('Customer1','1','5','12345');
  
  SELECT g.ProductID, g.Qty AS GRNQTY,
  i.qty AS InvQty FROM tblgrn g LEFT JOIN tblinv i
  on g.voucherno=i.invoiceno WHERE supplier='SUPPLIER1'
  AND i.productid=g.productid GROUP BY g.productid, g.qty, i.qty;
  </code></pre>
  
  <p>Ok, so now i have edited and simplified my code which i have also tried it on SQLFiddle, here the link.<br>
  <a href="http://sqlfiddle.com/#!9/682bac/4" rel="nofollow noreferrer">http://sqlfiddle.com/#!9/682bac/4</a></p>
  
  <p>I want the code to show all the data in the TBLGRN table while joining those entries that have a corresponding voucherno on the tblinv table. If there is no corresponding voucherno in the tblinv table then the voucherno should show as null. At the moment it is just showing productID 1 that have been sold. I would like to see items that have already been sold and the ones that have not been sold.</p>
  
  <p>I hope this time i explained well.</p>