I created this ORACLE SQL query that gives me all the data I need:
SELECT ci.record_no,
ci.communication_no,
ctt.description AS "TOPIC",
ctc.description AS "CATEGORY",
cc.sequence_no
FROM communication_instance ci,
communication_category cc,
ct_category ctc,
ct_topic ctt,
ct_type ctp,
department d,
communication_record cr
WHERE ci.record_no = cc.record_no
AND ci.record_no = cr.record_no
AND cc.topic = ctc.topic
AND cc.topic = ctt.code
AND cc.category = ctc.category
AND ci.communication_type = ctp.code
AND ci.creator_department = d.code
AND ci.record_no = '1565852'
ORDER BY 2
The data output looks like this:
|RECORD_NO | COMMUNICATION_NO | TOPIC | CATEGORY | SEQUENCE_NO|
1565852 1 Inter Stat 1 1565852 1 Clien Call 2 1565852 2 Inter Stat 1 1565852 2 Clien Call 2 1565852 3 Inter Stat 1 1565852 3 Clien Call 2
Please note the following relationships:
- 1
communication_no
is 1 instance of therecord_no
(ie. there should only be 3communication_no
rows) - For every unique
record_no
, there can be multiplesequence_no
's - Since multiple
sequence_no
's can exist for a singlerecord_no
, eachcommunication_no
would have 1 & 2 as theirsequence_no
's
I am trying to get the data to display the 3 unique communcation_no
records, and have the topic
, category
and sequence_no
's displayed in separate columns (instead of by rows). So the columns would become:
- RECORD_NO
- COMMUNICATION_NO
- TOPIC_1
- CATEGORY_1
- SEQUENCE_NO_1
- TOPIC_2
- CATEGORY_2
- SEQUENCE_NO_2
For example, communication_no
= 1, would have 1 row and the fields would be (in order):
- 1565852
- 1
- Inter
- Stat
- 1
- Clien
- Stat
- 2
Is this possible?