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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:16:26+00:00 2026-05-27T14:16:26+00:00

I’ve been hours trying to build this query and I need your help so

  • 0

I’ve been hours trying to build this query and I need your help so I can make it.
This is table Students (made out of inner joins):

SpecialtyChosenID  StudentID    Subject    SubjectSpecialtyID
5ABFB416-8137         15        Math          A1EBF3CB-E899
5ABFB416-8137         15        English       A1EBF3CB-E899 

The info in it means that a student with id no. 15 has chosen an specialty with id 5ABFB416-8137

The two subjects he has passed (Math and English) belong to a specialty with id A1EBF3CB-E899

What would be the query to know if the passed subjects belong to the specialty chosen by the student??

Counting the number of subjects with the same SubjectSpecialtyID as SpecialtyChosenID and vice versa could do.

Thanks a lot

  • 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-05-27T14:16:27+00:00Added an answer on May 27, 2026 at 2:16 pm

    You can do a self join. This finds the number of subjects taken by the student that match the student’s chosen specialities.

    SELECT l.SpecialtyChosenID, l.StudentID, Count(Distinct r.Subject) FROM Students l
    LEFT JOIN Students r ON (l.StudentID=r.StudentID AND l.SpecialityChosenID=r.SubjectSpecialityID)
    GROUP BY l.SpecialtyChosenID, l.StudentID
    

    However, this is quite inefficient using the table structure given. If you have a table listing students with their specialities, and another with subjects and specialities, and a third relating students with subjects, it would be better to build this query from the base data, rather than from the derived data.

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

Sidebar

Related Questions

I've been trying to fix this for two hours straight and I can't figure
I've been trying to get this code to work for hours! All I need
I've been trying to figure this out for hours now, and I'm at my
I've been scratching my head for hours trying to figure this out. I have
I've been pulling my hair out for hours trying to figure this out. I
I've been trying to figure this out for hours. I have a DYNAMIC youtube
I've been for the past few hours trying to figure out why openCV doesn't
I've been banging my head against the wall for hours trying to figure out
I've been banging my head on my desk for hours trying to figure out
This is crazy, I have been trying for hours to get this to work.

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.