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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:52:04+00:00 2026-06-02T00:52:04+00:00

I have a simple table schema: Person: ID, Name PhoneNumber: ID, Type, Number #Type

  • 0

I have a simple table schema:

Person: ID, Name
PhoneNumber: ID, Type, Number                    #Type can be 'home' or 'mobile'.
PersonPhoneNumber: ID, Person_ID, PhoneNumber_ID #A join table that connects the
                                                 #person to a phone number.

As data I have:

Person: 1, "Ed"
PhoneNumber: 1, "home", 1111
PhoneNumber: 2, "mobile", 2222
PersonPhoneNumber: 1, 1 /*(Person_ID)*/, 1 /*(PhoneNumber_ID*/
PersonPhoneNumber: 2, 1 /*(Person_ID)*/, 2 /*(PhoneNumber_ID*/

I want to write a view that returns:

Name    |Home    |Mobile
-----------------------------
"Ed"     1111     2222
"Joe"    3333     4444
... etc

Any tips on how I approach this?

Note: These tables are a snippet from a larger schema which explains why its a many to many and not more simplistic.

  • 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-02T00:52:05+00:00Added an answer on June 2, 2026 at 12:52 am

    You could do this in a more complicated way if you have multiple numbers or might have more than home/mobile, but for now, if you only have two numbers, then this will work:

    SELECT Name, HomeNumber.Number AS Home, MobileNumber.Number AS Mobile
    FROM Person
        LEFT JOIN PersonPhoneNumber HomeMap
            ON Person.ID = HomeMap.Person_ID
        LEFT JOIN PhoneNumber HomeNumber
            ON HomeMap.PhoneNumber_ID = HomeNumber.ID AND HomeNumber.Type = 'home'
        LEFT JOIN PersonPhoneNumber MobileMap
            ON Person.ID = MobileMap.Person_ID
        LEFT JOIN PhoneNumber MobileNumber
            ON MobileMap.PhoneNumber_ID = MobileNumber.ID AND MobileNumber.Type = 'mobile'
    

    BTW, if you dont want people with any numbers, then you can make the PersonPhoneNumber mapping a JOIN instead of a LEFT JOIN

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

Sidebar

Related Questions

The table's schema is pretty simple. I have a child table that stores a
I have a simple question related to database schema, how can I check whether
We have a simple Table per Type Entity Framework 4.0 model :- ALl classes
We have a database with a very simple schema: CREATE TABLE IF NOT EXISTS
Hey i have a simple ASP.NET application Table with this schema: id | Owner
I have a pretty simple table in SQLite, with the following schema: CREATE TABLE
I have simple table creating script in Postgres 9.1. I need it to create
I have a simple table with autoincrementing ID's and one text column. id(int), value(nvarchar)
I have a simple table in Sybase, let's say it looks as follows: CREATE
I have a simple table view which is editable. All I need the user

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.