Forum Discussion

SmithToronto's avatar
SmithToronto
Copper Contributor
Aug 07, 2024

To find the Missing rows

Every CEO should have both 'SEYT' and 'ZZZZ' records in Acc_Personal. I want to find any CEO record if anyone is missing 'ZZZZ' record. See table below.   To more clear: if CEO has 'SAYT' in Acc_Pe...
  • LainRobertson's avatar
    LainRobertson
    Aug 08, 2024

    SmithToronto 

     

    Having accurate data and an in-depth description certainly makes things easier.

     

    T-SQL

     

    SELECT
    	[ceos].[ceo]
    FROM
    	(SELECT DISTINCT [ceo] FROM [tmp]) AS [ceos]
    	LEFT OUTER JOIN [tmp] AS [t1] ON
    		[ceos].[ceo] = [t1].[ceo]
    		AND [t1].[acc_personal] = 'SEYT'
    	LEFT OUTER JOIN [tmp] AS [t2] ON
    		[ceos].[ceo] = [t2].[ceo]
    		AND [t2].[acc_personal] = 'ZZZZ'
    WHERE
    	[t2].[ceo] IS NULL;

     

     

    Output

     

    Cheers,

    Lain

Resources