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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:33:00+00:00 2026-06-17T23:33:00+00:00

Problem Specification and Database Condition: There are 3 tables ( Highschooler , Friend and

  • 0

Problem Specification and Database Condition: There are 3 tables (Highschooler, Friend and Likes) in the database and Here is the database :

Highschooler
ID  name    grade
1510    Jordan  9
1689    Gabriel 9
1381    Tiffany 9
1709    Cassandra   9
1101    Haley   10
1782    Andrew  10
1468    Kris    10
1641    Brittany    10
1247    Alexis  11
1316    Austin  11
1911    Gabriel 11
1501    Jessica 11
1304    Jordan  12
1025    John    12
1934    Kyle    12
1661    Logan   12

Likes
ID1 ID2
1689    1709
1709    1689
1782    1709
1911    1247
1247    1468
1641    1468
1316    1304
1501    1934
1934    1501
1025    1101

Question is : For every pair of students who both like each other, return the name and grade of both students. Include each pair only once, with the two names in alphabetical order.

My query is :

select  H1.name,H1.grade,H2.name,H2.grade from 
(select ID1,ID2 from Likes 
where ID1 in (select ID2 from Likes) and
ID2 in (select ID1 from Likes)) as G JOIN Highschooler H1 JOIN Highschooler H2
where H1.ID=G.ID1 and H2.ID=G.ID2 order by H1.name,H2.name

My query’s output is :

Cassandra 9   Gabriel  9
Gabriel   9  Cassandra 9
Jessica  11  Kyle   12
Kyle     12  Jessica 11

Expected output is:

Cassandra 9   Gabriel  9
Jessica  11   Kyle  12

I am not being able to remove one pair. How can I do that in SQlite?

  • 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-17T23:33:01+00:00Added an answer on June 17, 2026 at 11:33 pm

    The simplest thing to do is to expand your final where clause to include:

    where h1.name < h2.name
    

    This will prevent the doubling of each pair in the output.

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

Sidebar

Related Questions

Since I know there are lots of expert database core designers here, I decided
It looks like POSIXlt allows millisecond precision specification, but I have a problem when
Specification of the problem: I'm searching through really great amount of lines of a
So, I've looked at some posts about the Specification Pattern here, and haven't found
I'm having a small problem decoupling the path specification for properties files that my
I'm having a problem understanding the OAuth 1.0 specification. The oauth Authentication has 3
Problem: Been struggling to get my code to load external shaders and it is
Problem: I've written State Machine for my android application. It is separate class, extension
Problem: I have a table that prints out vertical but I would like it
Problem Given a boolean expression consisting of the symbols 0, 1, &, |, ^

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.