I have a query that gives expected results. But fo...
# suiteql
r
I have a query that gives expected results. But for some use case I need the shipping address primary key. The below query gives me 10 result. But if I add shippadd.nkey in SELECT and in GROUP BY clause, it only gives 1 result. Can't we group by the nkey?
Copy code
SELECT 
  t.entity AS customer_internal_id, 
  c.entityid AS customer_id, 
  c.companyName AS customer_name, 
  t.shipdate AS shipping_date, 
  l.id AS location_internal_id, 
  l.name AS location, 
  shipadd.addrtext AS shipping_address, 
  COUNT(t.id) AS count_of_order, 
  SUM(t.custbody_oc_pallet_quantity) AS total_pallet_quantity, 
FROM 
  transaction AS t 
  INNER JOIN customer AS c ON t.entity = c.id 
  INNER JOIN TransactionLine AS line ON line.Transaction = t.id 
  INNER JOIN location AS l ON line.location = l.id 
  INNER JOIN TransactionShipment AS tranship ON t.ID = tranship.Doc 
  INNER JOIN transactionShippingAddress AS shipadd ON t.shippingaddress = shipadd.nkey 
WHERE 
  t.type = 'SalesOrd' 
  AND BUILTIN.DF (t.status) IN (
    'Sales Order : Pending Fulfillment'
  ) 
  AND line.mainline = 'T' 
  AND t.shipdate IS NOT NULL 
  AND tranship.shippingmethod IN ('x1 Carrier', 'x2 Carrier') 
GROUP BY 
  t.entity, 
  c.entityid, 
  c.companyName, 
  t.shipdate, 
  l.id, 
  l.name, 
  shipadd.addrtext 
HAVING 
  SUM(t.custbody_oc_pallet_quantity) > '7' 
  AND COUNT(t.id) > '1' 
ORDER BY 
  t.shipdate, 
  shipadd.addrtext
c
Is it possible that only one address fits the bill, and you're getting 10 results because there are multiple other records in your JOINs that match that single address?
r
No, 8 out of those 10 address are unique. I have grouped already by the shipadd.addrtext. So after that grouping only I am getting 10 rows, but the moment I add the corresponding nkey in the select and group by clause, only 1 result comes back, remaining 9 just disappears.
👍 1