I created the following query on the three existing tables, which also works fine.
Organization Table
-------------
id name service
--------------------------------
1 CEO 1, 2, 4
2 ALF 1, 3, 5
3 FRGT
4 OFFICE_IT 1, 2, 7
City Table
-------------
id name
-------------
10 Berlin
20 Paris
30 London
40 Rom
Relation Table
-------------
oid cid
-------------
1 10
2 20
3 30
4 40
SELECT o.name as Organization, o.service as service, c.name as City
FROM Organization o
INNER JOIN Relation rel ON o.id = rel.oid
INNER JOIN City c ON rel.cid = c.id
WHERE o.service IS NOT NULL
New View:
id Organization service City
-----------------------------------------------
1 CEO 1, 2, 4 Berlin
2 ALF 1, 3, 5 Paris
4 OFFICE_IT 1, 7 Rom
But now I would like to design the table in such a way that the values of the string in the "service" column are written separately in one line.
Please see the example:
id Organization service City
-----------------------------------------------
1 CEO 1 Berlin
1 CEO 2 Berlin
1 CEO 4 Berlin
2 ALF 1 Paris
2 ALF 3 Paris
2 ALF 5 Paris
4 OFFICE_IT 1 Rom
4 OFFICE_IT 7 Rom
In the meantime I managed to get a corresponding query for the "Organization" table only, without Relation to city.
SELECT O.ID
, O.name
, trim(COLUMN_VALUE) AS service
FROM Organization o ,
xmltable(('"'
|| REPLACE(o.service, ',', '","')
|| '"'))
However, I currently lack the idea of squeezing both individual queries into a single SQL query. Do you have a solution?