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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:14:54+00:00 2026-05-26T16:14:54+00:00

I would like to ask for help. I have 3 tables. students_name students_has_subjects subject

  • 0

I would like to ask for help. I have 3 tables.

  1. students_name
  2. students_has_subjects
  3. subject

What is the sql statement to query 3 tables to display student_id, student_name, stud_subject where student is taken and the subject description.

I would like 2 type of display of records.

First display

1, Paul Mark, Math, Mathematics, Mathematics
1, Paul Mark, English, English Language
1, Paul Mark, Science, About Science
2, John Mark, Math, Mathematics, Mathematics
2, John Mark, English, English Language
2, John Mark, Science, About Science

Second display

1, Paul Mark, Math, English, Science
2, John Mark, Math, English, Science

Below is the 3 table sample and its records. thanks a lot.

students_name table
student_id, student_name
1, Paul Mark
2, John Mark

students_has_subjects
id, stud_name, stud_subject

1, Paul Mark, 1
2, Paul Mark, 2
3, Paul Mark, 3
4, John Mark, 1
5, John Mark, 2
6, John Mark, 3

Subjects
subject_id, subject_name, description

1, Math, Mathematics
2, English, English Language
3, Science, About Science
  • 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-26T16:14:54+00:00Added an answer on May 26, 2026 at 4:14 pm

    You have to use 2 joins to link these 3 tables.
    INNER JOIN means, that only those tuples are listed, for which an correct tuple exists in every table. Students without subjects or wrong subject_ids will not be listed.

    Keep in mind, that an student, which visits X subjects will also listed X times.

    SELECT n.student_id, n.student_name, s.subject_name, s.description FROM student_name n INNER JOIN student_has_subjects shs ON shs.stud_name = n.student_name INNER JOIN subjects s ON shs.stud_subject = s.subject_id

    If it is an homework of you, please mark it as one!

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

Sidebar

Related Questions

I would like to ask for help regarding datasets and Crystal Reports. I have
I would like to ask for help on how to achieve this. I have
I would like to ask for help with converting my mysql_* query to prepared
Good morning! I would like to ask some help from you guys on how
I'm still fairly new to mysql and would like to ask for some help.
I would like to ask you: Imagine that you have a site and there
I would like to ask such question, I have XML xsd`s, which generate beans
I would like to ask you about regular expressions preg_match have outlined below. I
I would like to ask a help about Zensor which is a plugin that
I would like to ask some logic question here. Let say I have a

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.