Hi!
My question is if it is possible to retrieve just one row for the following case.
We have a table, PARTY, where we have a single row for each PARTYID´s contact.
The table look like this:
PARTYID,
CONTACT_ID,
NAME,
PHONE
One PARTYID can have up to three different CONTACT_ID´s.
Is it possible to create a view that return just one single row for each PARTY_ID?
(instead of the view I have created below which gives me three separate rows).
Or is the only way to achieve that to to create another view which uses a group by clause on the first view?
The row I want could look something like:
PARTYID,
CONTACT1_NAME,
CONTACT1_PHONE,
CONTACT2_NAME,
CONTACT2_PHONE,
CONTACT3_NAME,
CONTACT3_PHONE
Here is the code for the view I have created:
/Goran
My question is if it is possible to retrieve just one row for the following case.
We have a table, PARTY, where we have a single row for each PARTYID´s contact.
The table look like this:
PARTYID,
CONTACT_ID,
NAME,
PHONE
One PARTYID can have up to three different CONTACT_ID´s.
Is it possible to create a view that return just one single row for each PARTY_ID?
(instead of the view I have created below which gives me three separate rows).
Or is the only way to achieve that to to create another view which uses a group by clause on the first view?
The row I want could look something like:
PARTYID,
CONTACT1_NAME,
CONTACT1_PHONE,
CONTACT2_NAME,
CONTACT2_PHONE,
CONTACT3_NAME,
CONTACT3_PHONE
Here is the code for the view I have created:
Code:
CREATE OR REPLACE VIEW PARTY_V
(
PARTYID,
CONTACT1_NAME,
CONTACT1_PHONE,
CONTACT2_NAME,
CONTACT2_PHONE,
CONTACT3_NAME,
CONTACT3_PHONE
)
AS SELECT
PARTYID,
NAME,
PHONE
NULL,
NULL,
NULL,
NULL
FROM
PARTY
WHERE
CONTACT_ID = 'CONTACT1'
UNION
SELECT
PARTYID,
NULL,
NULL,
NAME,
PHONE
NULL,
NULL
FROM
PARTY
WHERE
CONTACT_ID = 'CONTACT2'
UNION
SELECT
PARTYID,
NULL,
NULL,
NULL,
NULL,
NAME,
PHONE
FROM
PARTY
WHERE
CONTACT_ID = 'CONTACT3'
/
/Goran