Skip to main content
nicholaso0002
August 18, 2022
Question

SQL or Appian Expression to Achieve a Unique Select

  • August 18, 2022
  • 1 reply
  • 0 views

what I am looking for is a generic qry that will return the primary record when the case number is duplicate as shown in the image (242xxx)

    1 reply

    csteward
    August 19, 2022

    I would do this on the DB side in a view:

    SELECT
    caseNum,
    causeType
    /* additional columns here */
    FROM YOUR_TABLE a
    WHERE a.causeType =
    	CASE 
    	WHEN (SELECT COUNT(*) FROM YOUR_TABLE b where b.caseNum=a.caseNum)=1 THEN a.causeType
    	ELSE 'Primary'
    END