Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:09:53+00:00 2026-06-05T10:09:53+00:00

I have two tables Profile_Appointments and Profile. Each record in the profile table has

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:09:55+00:00Added an answer on June 5, 2026 at 10:09 am

    You need to satisfy both conditions so you need AND instead of OR

        select pa.appointment_key, p.profile_key as Rep, p2.profile_key as Customer, 
            p.first_name as RepName,p2.first_name as CustomerName
    from profile_appointment pa    
    join profile_appointment pa2 on pa.appointment_key = pa2.appointment_key
    join profile p    on p.profile_key = pa.profile_key    and  p.profile_type_key = '4'
    join profile p2   on p2.profile_key = pa2.profile_key   and  p2.profile_type_key = '6'  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables one is table Profile and other is table Profile_location (stores
I have two tables. One is Employee_Mstr and other is EmployeeLeaveRequest_mstr . My data:
I have two tables, namely Price List (Table A) and Order Record (Table B)
Into I have two tables profile and name , the profile table contains some
using php and mysql I have two tables, a users table and a profiles
I have two tables that are all the same, except one has a timestamp
I have two tables: A, B. I need to select all data from B.
I have two tables, Profiles and ProfileInformation . Any profile may have multiple entries
I have two tables in my database users table : +-----------+---------------------+---------+---------+ | id |
THE INFO Currently I have two tables I am working with- a POST table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.