Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL:How to select only first phone number for Find Service?

522854Oct 20 2010 — edited Oct 21 2010
Hi, Can some one help me fix this query?

The Problem is - there are party ids with no phone number, one phone number and more than one phone number. My requirement is to pick nulls and only first phone numbers if a party having more than one phone number. The query below is correctly picking nulls and single phone numbers but also selecting all the phone numbers for party id 13909 which has 3 phone numbers

It suppose to pick first phone number 416-890-0089 and restrict 416-960-8686, 647-456-3040

How to select only first party id for the parties who have more than one phone number

Thanks in Advance!

select distinct p.party_id,
p.family_name,
p.given_name,
p.status,
p.type,
ci.value,
pr.role,
ad.unit_number,
ad.unit_identifier,
ad.street_number,
ad.street_number_suffix,
ad.street_name,
ad.street_type,
ad.street_direction,
ad.city,
ad.province_id,
ad.postal_code,
ad.country_id,
ad.postal_box_number,
ad.station_type,
ad.station_identifier,
ad.address_line_1,
ad.address_line_2,
ad.address_line_3,
ad.rural_route_identifier,
ad.rural_route_type,
ad.status,
ad.address_id,
ad.attention

from party p, address ad, party_address pd, contact_information ci, party_contact pc, SR1CUST1.party_role pr

Where
P.party_id=PD.Party_id
AND AD.address_id=PD.address_id
and p.party_id = pr.party_id
And (CI.Contact_Mode = 'T'
Or CI.Contact_Mode is null)
AND P.party_id=PC.Party_id(+)
And PC.CONTACT_INFO_ID=CI.contact_info_id(+)
AND AD.address_type = 'P'
and P.type='B'
and pr.role = 'C'
and p.family_name like 'Lew%'
and p.given_name like 'J%
Order by p.party_id ASC


Response


1478 Null
1479 Null
1577 Null
1712 Null
1822 Null
6346 647-345-7384
6347 416-890-9384
6348 519-897-0089
6832 416-930-1265
8733 647-976-8923
13909 416-890-0089
13909 416-960-8686
13909 647-456-3040
This post has been answered by hm on Oct 20 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2010
Added on Oct 20 2010
2 comments
343 views