So, here is my SELECT query... it's working, but i want to get (with left join) only message types, which are NOT exists in CONFIG table:
SELECT PARTNER.ID AS [ID],
PARTNER.NAME AS [name],
PARTNER.GLN AS [GLN],
IIF(CONFIG.DIRECTION=0,'IN','OUT') AS [Direction],
COUNT(CONFIG.ID) AS [count config]
,STUFF((SELECT ', ' + message_type.message_type
FROM message_type
WHERE message_type.id not in (0,7,8,11,12,14,15)
ORDER BY message_type.id
FOR XML PATH (''), TYPE
).value('.', 'varchar(max)')
, 1, 1, '')
FROM PARTNER LEFT JOIN CONFIG ON PARTNER.ID=CONFIG.PARTNER_ID_EXT
WHERE PARTNER.ID IS NOT NULL AND PARTNER.CHARSET IS NOT NULL
AND PARTNER.NAME NOT LIKE 'TEST%'
GROUP BY PARTNER.ID, PARTNER.NAME, PARTNER.GLN, CONFIG.DIRECTION
HAVING COUNT(CONFIG.ID) not in (5,11,16,20)
ORDER BY [name] asc, [Direction] asc
UPDATED
My sample DATA:
I want to display the message types, which are MISSING from CONFIG.
Expected result:


message_type.{Your Column} = CONFIG.{Your Column}to yourWHERE?STRING_AGGaggregate method