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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:20:41+00:00 2026-06-18T14:20:41+00:00

I’m taking a database course and I’ve got stuck on one of the questions.

  • 0

I’m taking a database course and I’ve got stuck on one of the questions. “For all cases where A is friends with B, and B is friends with C, add a new friendship for the pair A and C”.
This is as far as I’ve got

INSERT INTO 
    friend
SELECT DISTINCT 
    f1.ID1, f2.ID1 
FROM 
    friend f1 
    JOIN friend f2 using (ID2), 
    friend 
WHERE 
    f1.ID1 <> f2.ID1 
AND friend.ID1 <> f1.ID1 
AND friend.ID2 <> f1.ID2

The schema is here http://www.sqlfiddle.com/#!5/cf8b5/23

I wonder if somebody could give me a few hints on how to proceed.
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-18T14:20:42+00:00Added an answer on June 18, 2026 at 2:20 pm

    I think you have the basic concepts.

    I’d do it like the following:

    INSERT INTO friend
    (ID1, ID2)
    SELECT DISTINCT f1.ID1, f2.ID2
    FROM friend f1
      INNER JOIN f2
        ON f1.ID2 = f2.ID1
          AND f1.ID1 <> f2.ID1
          AND f1.ID2 <> f2.ID2
    WHERE f1.ID1 <> f2.ID2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm taking a database course this semester, and we're learning SQL. I understand most
I'm currently taking an on-line course for Database administration. The question I am stuck
I am going over a past paper for a database course I am taking
I am new to EF using EF4 with Database First and generation taking place.
I'm taking a database theory course, and it's not clear to me after doing
Taking the database first approach in MVC3 all of my models are created and
I am taking the free Stanford database course online. I don't have any DB
I'm taking a course called "database systems" and for our class project I have
I am taking database course and came across the term relation. Are relations same
I'm taking a user interface design course this semester, and so the emphasis is

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.