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 3955982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:18:23+00:00 2026-05-20T02:18:23+00:00

I have 3 tables [contact] —————— cID (PRIMARY KEY, INT) || name || lastupdate

  • 0

I have 3 tables

[contact]
------------------
cID (PRIMARY KEY, INT) || name || lastupdate (TIMESTAMP)

[phone]
----------------------
cID (FOREIGN KEY, linked to contact.cID) || phonenumber || pID (phone number ID, since each contact can have many numbers)

[email]
------------------------
cID (FOREIGN KEY) || email

I need to make a select query that will fetch all the cID of each contact, their name, their phone number if the pID is 1 and their email all in one table.
So the output would look like this for example.

cID   |   name             |   phone1  |  email
----------------------------------------------
45    |  John Smith         |  1234567  |  john.s@test.com
46    |  Darth Vader        |  9999999  |  vader@deathstar.org
47    |  Yoda               |  1236547  |  
-----------------------------------------------------------------------------

I tried doing it like this

SELECT contact.cID, name, phone, email FROM contact, phone, email 
WHERE contact.cID = phone.cID AND contact.cID = email.cID AND phone.pID = 1;

This almost does it, but if a contact doesn’t have either a phone number or an email by their name then they’ll be left out.
I need to show all the contacts, regardless weather they have an email or a phone number in the database.

How can I accomplish this?

  • 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-05-20T02:18:24+00:00Added an answer on May 20, 2026 at 2:18 am
    Select c.cID, C.name, P.phone As phone1, E.email
    From contact As C
        Left Join phone As P
            On P.cID = C.cID
                And P.pID = 1
        Left Join email As E
            On E.cID = C.cID
    

    In short, you need to put the criteria for the pID = 1 in the ON clause when joining phone to contact. In additon, you need to use Left Joins to handle the case where they do not have a phone or email.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: Contact (id,name) Link (id, contact_id, source_id) I have the following
Say i have Four tables 1) Studnets: Student_ID First Name Last Name 2) Contact
I have following tables: Profiles: ProfileID (Primary Key) ProfileName, etc. Contacts: ContactID (Primary Key)
I have 2 tables in my DB, Customers, Contacts. CusID is a Foreign Key
We have a SQL Server table containing Company Name, Address, and Contact name (among
When I have tables in my database that have PK/FK relationships (int) and when
I have some tables with data: Category CategoryID CategoryName 1 Home 2 Contact 3
I have a table for a contact form and this table contains another table
I have a contacts table which contains fields such as postcode , first name
In my database I have tables that define types for example Table: Publication Types

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.