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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:38:41+00:00 2026-06-17T17:38:41+00:00

For each student A who likes a student B where the two are not

  • 0

For each student A who likes a student B where the two are not friends, find if they have a friend C in common (who can introduce them!)

I’ve tables

 Friend (ID1, ID2) 

 Likes(ID1, ID2)

I need to select pairs of id from Likes that don’t friends.

I’ve done it

    SELECT L.id1 id1, L.id2 id2
 FROM likes L
 LEFT JOIN friend F ON (L.id1 = F.id1 and L.id2 = F.id2)
 WHERE F.id1 IS NULL

How to find Friend IDs in common?

  • 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-17T17:38:42+00:00Added an answer on June 17, 2026 at 5:38 pm

    We need to find all tuples such that the following conditions apply:

    1. Person A likes person B
    2. Person A is friends with person C
    3. Person B is friends with person C
    4. Person A is not friends with B, and B is not friends with A

    A query that accomplishes this would be something like this:

    SELECT L.ID1 as Liker, L.ID2 as Liked, F1.ID2 as MutualFriend
    FROM Likes L, Friend F1, Friend F2 
    WHERE F1.ID2 = F2.ID2
    AND F1.ID1 = L.ID1
    AND F2.ID1 = L.ID2
    AND NOT EXISTS(
        SELECT * FROM FRIEND F3
        WHERE (F3.ID1 = L.ID1 AND F3.ID2 = L.ID2)
        OR (F3.ID1 = L.ID2 AND F3.ID2 = L.ID1));
    

    PS I only tested in in sqlite3, so there may be a slight syntax error in another DBMS, but I don’t think so. Also, my answer returns a slightly more readable answer than just the mutual friend id.

    Hope that helps,

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

Sidebar

Related Questions

I have three roles: Instuctor, Student, Admin and each have controllers with a home
I have a database as: Student (ID, Name, Grade) Likes (ID1, ID2) Where ID1
I have a table student(id, name, department, age, score). I want to find the
here for each row each student marks have to be entered ID -------- MID1
Let's say we have the following Student.mdd: person=not null ptr general.Person interests=set general.ActivityField education=set
Problem: * I'm trying to calculate the number of consecutive absence each student have
I have a website (my college website) for which each student has a username/password
I have a table called interests of school subjects for each student. A student
I have two tables: STUDENT GRADES ---------- ---------- id id name person_id address date
I have a list of grades that students received. Each student appears multiple times

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.