Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

How do i get the ID from parent table and JOIN from child table to run the query.

Course Queries Syllabus Queries

Max. 2000 characters
Tuteehub
Replies

usr_profile.png

User

( 5 months ago )

 

I have two tables, one is students and another is schools. I am using a FK to call school id ( scid ) to the students table.

Students

+------+---------+-----+-----------+
| stid | student | age | school_id |
+------+---------+-----+-----------+
|  1   | John    |  26 |         2 |
|  2   | Susan   |  24 |         1 |
+------+---------+-----+-----------+

schools

+------+------------+-----------+
| scid | schoolname | syllabus  |
+------+------------+-----------+
|  1   | school1    | syllabus1 |
|  2   | school2    | syllabus2 |
+------+------------+-----------+

The view page displays all the details where i am using a id to get the details from the students table and using a join to get the information from school table.

Student name: John
Age: 26
School: School 2

I need to use the id for students and use the join to get the name from the school. How do i do that. I came up with this, but how do i use the id with this.

SELECT schools.name
FROM schools
    LEFT JOIN students
        ON students.school_id=schools.scid;

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif