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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:34:22+00:00 2026-05-31T13:34:22+00:00

I was originally doing this through four separate queries – I think it’s time

  • 0

I was originally doing this through four separate queries – I think it’s time I optimize my code through the use of joins…

I have four tables (as shown below):

[sl_student_course]
student_id (int 11)
------------------
course_id (int 11)
------------------

[sl_project_course]
project_id(int 11)
------------------
course_id (int 11)
------------------

[sl_project]
project_id (int 11) - Primary Key -
_____________________
professor_id (int 11)
---------------------
project_name (varchar 50)

[sl_professor]
professor_id(int 11) - Primary Key -
_____________________
professor_name (varchar 50)
---------------------
project_email (varchar 50)

What information do I need?

I need all data from sl_project and sl_professor where sl_student_course.course_id = sl_project_course.course_id AND then I need to use the project_id from sl_project_course

SO…

sl_student_course.course_id –> sl_project_course.project_id –> sl_project.professor_id, sl_project.project_name, –> sl_professor.professor_name, sl_professor.professor_name

Does this make any sense?

  • If it doesn’t, here’s another example!
sl_student_course
course_id |  1

sl_project_course
project_id | 1
course_id  | 1

sl_project
project_id | 1
professor_id | 2
project_name | project1

sl_professor
professor_id | 2
professor_name | John Doe
professor_email | John@Doe.com

  • 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-31T13:34:23+00:00Added an answer on May 31, 2026 at 1:34 pm

    Hoping I understood your table relationships correctly, which has professors joined to projects (in the sl_project table).

    This will get you project and professor data (using TSQL):

    SELECT P.project_name, F.professor_name, F.professor_email
    FROM sl_project P
        INNER JOIN sl_professor F ON F.professor_id = P.professor_id
    
        -- Not sure where course is coming into play, since you aren't selecting
        -- anything from the students/course table, but if you need to ensure there is a
        -- course for this project and students in the course, these joins are necessary.
        INNER JOIN sl_project_course C ON C.project_id = P.project_id
        INNER JOIN sl_student_course S ON S.course_id = C.course_id
    WHERE P.project_id = @project_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Originally posted on Server Fault , where it was suggested this question might better
I originally asked this question on RefactorMyCode , but got no responses there... Basically
I originally asked this question , but in finding an answer, discovered that my
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Yet another reason why I hate IE for being different. I've got this code:
i have three models, all for a has_many :through relationship. They look like this:
I asked a question about this that was originally answered here . Originally, I
In Python 2.5 I stored data using this code: def GLWriter(file_name, string): import cPickle
NOTE: Originally had this listed as a memory leak. After looking into this deeper,
I already started this in javascript so I don't want to use jquery but

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.