MSSQL:
SELECT ci.ciname AS 'Name',
(SELECT rel.relationship + Char(10) + ' ' + ci2.ciname
+ Char(10) FROM cirelationships AS cirel
LEFT JOIN ci AS ci2
ON ci2.ciid = cirel.ciid2
LEFT JOIN relationshiptype AS rel
ON rel.relationshiptypeid = cirel.relationshiptypeid
WHERE cirel.ciid = ci.ciid
FOR xml path('')) AS 'Relationship Details' FROM ci
WHERE ciid IN (SELECT ciid
FROM cirelationships)
PGSQL :
SELECT ci.ciname AS 'Name',
(SELECT rel.relationship + Char(10) + ' ' + ci2.ciname
+ Char(10) FROM cirelationships AS cirel
LEFT JOIN ci AS ci2
ON ci2.ciid = cirel.ciid2
LEFT JOIN relationshiptype AS rel
ON rel.relationshiptypeid = cirel.relationshiptypeid
WHERE cirel.ciid = ci.ciid
FOR xml path('')) AS 'Relationship Details' FROM ci
WHERE ciid IN (SELECT ciid
FROM cirelationships)