Author Topic: SQL Query to find elements that are missing a connection  (Read 1403 times)

netizensmith

  • EA User
  • **
  • Posts: 22
  • Karma: +1/-0
    • View Profile
SQL Query to find elements that are missing a connection
« on: June 11, 2025, 10:08:19 pm »
Hi all,

My SQL is super rusty. I'm trying to find all elements of stereotype "A" that to not have any connections of type "B" (let's say an association for example) with an element of stereotype "C" at the other end. I can find the inverse easy enough (Every A that has a C at the other end) but not sure where to start. Can anyone help?
Here's the opposite of what I want:

Code: [Select]
SELECT  goal_obj.ea_guid AS CLASSGUID, goal_obj.Name AS goalName,
outcome_obj.name AS outcomeName, package_obj.Package_ID AS PackageID
FROM t_object goal_obj

INNER JOIN t_package package_obj ON goal_obj.package_id = package_obj.package_id
INNER JOIN t_connector goal_outcome_connector ON goal_obj.object_id = goal_outcome_connector.end_object_id
INNER JOIN t_object outcome_obj ON goal_outcome_connector.start_object_id = outcome_obj.object_id AND outcome_obj.Stereotype = 'ArchiMate_Outcome'

WHERE goal_obj.Stereotype = 'ArchiMate_Goal'
--AND outcome_obj IS NULL
AND package_obj.Package_ID = 2396;-- 2396 is the Package ID of REDACTED

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SQL Query to find elements that are missing a connection
« Reply #1 on: June 11, 2025, 10:38:29 pm »
You'll have to use a
where not exists( <selec query>)

Geert

netizensmith

  • EA User
  • **
  • Posts: 22
  • Karma: +1/-0
    • View Profile
Re: SQL Query to find elements that are missing a connection
« Reply #2 on: July 01, 2025, 09:28:33 pm »
I forgot to thank you for this Geert, thanks.