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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:53:29+00:00 2026-05-15T21:53:29+00:00

Suppose I have a table whose function is specifically to link two other tables

  • 0

Suppose I have a table whose function is specifically to link two other tables in terms of OOP.

Suppose that I have two tables: one for person’s name and another one for phone numbers:

Table 1:
id   person's name
1    John
2    Smith

Table 2:
id   Phone number
5     23424224
6      23424242

And then I have a third table that links the person and their respective phone numbers:

Table 3:
id    person-id    phone-number-id
1         1           5
2         2           6

Hence John has phone number 23424224 and Smith has phone number 23424242.

And I want to run an SQL query to fetch all persons from Table 1 whose phone number start with, let’s say, (234).

How would I go about linking the select queries within this table structure…what query would I run?

  • 1 1 Answer
  • 1 View
  • 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-15T21:53:29+00:00Added an answer on May 15, 2026 at 9:53 pm

    First, the only reason to do that table is if you have a many-to-many relation.
    While a person can have many phone numbers, can really one phone number have many persons?
    If that is true, then your schema implements that requirement, but that seems a little over-engineered to me 🙂

    Second, this is a fairly simple join. What you want to do is first select out the phone numbers in question, then given that, select out the person IDs from the third table, then given that, select the names from the first table. Something like:

    SELECT t1.name as name, t2.number from table1 t1, table2 t2, table3 t3 where t2.number like ‘234%’ and t3.personid = t1.id and t3.phoneid = t2.id;

    You can also rewrite the “blah.id = blah.id” as a join if you need outer join semantics (include certain fields with NULLs).

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

Sidebar

Related Questions

Suppose I have table A with a field that can be either 1 or
Suppose I have table Person table Employee, which inherits Person. I want to get
Suppose I have a table, the first column is an identity. I thought that
Suppose I have a MySQL table called MyTable, that looks like this: +----+------+-------+ |
I have a question... Suppose that I have a table that holds names of
Let's suppose that I have a foreign key whose actions are: on delete set
Suppose I have a table Item (Id int Primary Key, Number INT) having records
Suppose I have this table parent | child 1 2 1 3 2 4
Suppose I have this table: id | name | city ------------------ 1 | n1
Suppose I have a table events {id, userid, create_time, country, type, page, browser} I

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.