06-11-2018 10:43 AM
I am very new to SQL and trying to learn my way around the tables. I'd like to retrieve a list of all document types from select document groups and show show which scan queue they belong to. The problem I'm having with my query is that no row is returned if the document type is not assigned to a scan queue. I'd like to see a blank entry.
SELECT dt.itemtypenum AS "Document ID", dt.itemtypename AS "Document Type", itg.itemtypegroupname
AS "Document Type Group", sq.queuename AS "Scan Queue"
FROM hsi.doctype dt
INNER JOIN hsi.itemtypegroup itg ON dt.itemtypegroupnum = itg.itemtypegroupnum
INNER JOIN hsi.scanqueuexit si ON dt.itemtypenum = si.itemtypenum
INNER JOIN hsi.scanqueue sq ON sq.queuenum = si.queuenum
WHERE dt.itemtypenum > 100
AND dt.itemtypegroupnum IN (102,104,111,112)
ORDER BY "Document Type"
06-11-2018 10:53 AM
Hi Edward,
I think the problem is in the type of JOIN statement you're using. Try changing the INNER JOINs into LEFT JOINS like this:
SELECT dt.itemtypenum AS "Document ID", dt.itemtypename AS "Document Type", itg.itemtypegroupname
AS "Document Type Group", sq.queuename AS "Scan Queue"
FROM hsi.doctype dt
LEFT JOIN hsi.itemtypegroup itg ON dt.itemtypegroupnum = itg.itemtypegroupnum
LEFT JOIN hsi.scanqueuexit si ON dt.itemtypenum = si.itemtypenum
LEFT JOIN hsi.scanqueue sq ON sq.queuenum = si.queuenum
WHERE dt.itemtypenum > 100
AND dt.itemtypegroupnum IN (102,104,111,112)
ORDER BY "Document Type"
An INNER join is going to show only those records that exist in both tables. A LEFT join (aka LEFT OUTER JOIN) is going to show all of the records in the left table and only those in the right table that match.
Jeff
06-11-2018 11:46 AM
06-11-2018 12:39 PM
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.