I have two tables Profile_Appointments and Profile.
Each record in the profile table has a Profile_key and a Profile_Type_Key in addition to other profile data – first name, last name, etc.
Rep’s have Profile_Type 4, Customer’s have Profile_Type 6
PROFILE TABLE
Profile_Key Profile_Type_key First_Name Last_Name
1234 4 John Smith
8765 6 Mike Jones
The Profile_Appointment table holds two records for each appointment one with the Rep’s
Profile_Key the other with the customer’s Profile_Key
Appointment_Key Profile_Key
10 1234
10 8765
The appointment_key refers to the Appointment table.
I need make a query that results in one record for each appointment and has both the rep and customer’s data from the Profile table
THE RESULT I WANT
Appointment_Key Profile_Key Rep Profile_Key Customer
10 1234 8765
This is the query that’s not working…
select appointment_key, p.profile_key as Rep, p2.profile_key as Customer, p.firs_name,p2.first_name from profile_appointment pa
join profile p
on p.profile_key = pa.profile_key
join profile p2
on p2.profile_key = pa.profile_key
where p.profile_type_key = '4' or p2.profile_type_key = '6'
What I get is:
Appointment_Key Rep Customer Rep Customer
10 1234 1234 John John
I can’t figure out what I’m missing.
Thanks.
You need to satisfy both conditions so you need AND instead of OR