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

  • Home
  • SEARCH
  • 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 7976185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:51:26+00:00 2026-06-04T08:51:26+00:00

I am wanting to create a query that returns a parent and its guardian

  • 0

I am wanting to create a query that returns a parent and its guardian using the follow tables. My question is how can I use the name attribute in the person table twice to return the name of the caregiver and the name of the parent. Any example code would be appreciated thanks. I know I havn’t explained it very well as but if anyone understand what I mean feel free to edit the above. More specifically I want to use only the person table to store information about parents and their children and use display the name of each who are related. How can I do this with a single table.

enter image description here

Using some advice provided, I was able to create the query but due to a problem with my table it doesn’t work. I am using the following tables:

CREATE TABLE Person
(
personID INT NOT NULL,
name VARCHAR(50),
address VARCHAR(70),
phone VARCHAR(15),
email VARCHAR(30),
year INT,
PRIMARY KEY (personID)
);

CREATE TABLE Guardian
(
parentID INT NOT NULL,
childID INT NOT NULL,
PRIMARY KEY (parentID, childID)
FOREIGN KEY (parentID) REFERENCES (personID),
FOREIGN KEY (childID) REFERENCES (personID)
);

What statements should I use where to get this to work properly. I think the problem is that both foreign key statements are referring to the same key in the person table. How do I refer to the same attribute when looking for both the parent and child without getting any errors.

  • 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-04T08:51:27+00:00Added an answer on June 4, 2026 at 8:51 am

    First fix your create table:

    CREATE TABLE Guardian
    (
    parentID INT NOT NULL,
    childID INT NOT NULL,
    PRIMARY KEY (parentID, childID),
    FOREIGN KEY (parentID) REFERENCES Person(personID),
    FOREIGN KEY (childID) REFERENCES Person(personID)
    );
    

    then query:

    SELECT
      p.name as parentName,
      c.name as childName,
      Guardian.*
    FROM Person AS p
      INNER JOIN Guardian ON p.PersonID=Guardian.parentID
      INNER JOIN Person AS c ON c.PersonID=Guardian.childID
    WHERE
      -- whatever you want, e.g.
      p.Name='John'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wanting to create a VB.Net app that checks a database and then
I'm wanting to create an android app that gathers information and then uploads to
I'm wanting to create a form builder that creates HTML forms programmatically with PHP,
I have been wanting to create an application using the Microsoft Speech Recognition. My
So I have 2 tables, invoices and invoiceitems. I am wanting to create a
I've been wanting to create a HUD style loading bar like the SMS app
What I am wanting to do is create a PDF ideally from HTML code.
I'm wanting to get the filepath ie /sites/default/files/myfile.pdf for my file uploads. I'm using
I often find myself wanting to debug CSS layout issues that involve DOM changes
I'm wanting to create a shoutbox, though I'm wondering if there is another way

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.