Click here to Skip to main content
15,035,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables in my database those name are TblStudent and TblStudentCourse.


(1) TblStudent and its data fields are below

StudentId ......................Name................................... Password

1161213003..................... Ali...........................................12
1161213004......................Ahsan.........................................11

(2) TblStudentCourses this is second Table and its data fields are below
id............StudentId............CourseName...............Semester....................CourseCode

1........,...1161213003.............Math..........................................1................................301
2............1161213003.............Physics.......................................1...............................302

In TblStudentCourse id is auto increment.
First the student create his account ,his account releted data is stored in TblStudent ; then he add his subjects ,subject related data is stored in TblStudentCourse.
I want that every student see his registered courses detail like course name, semester and coursecode in gridview.

I have write a query for this but not working good....
"SELECT sc.*,s.StudentId FROM TblStudent s INNER JOIN TblStudentCourses sc ON s.StudentId=sc.StudentId ";
The problem is that when a student go to see his registered courses detail then this query shows the courses detail of the others student
Posted
Comments
mudi lala 1-Sep-14 6:59am
   
Select A.Name,B.CourseName,B.Semester,B.CourseCode FROM TblStudent A
INNER JOIN TblStudentCourses B ON A.StudentId=B.StudentId

Pramod Singh (C)593
This query not work..It also display the courses detail of other student
Neetin_1809 1-Sep-14 8:36am
   
Hello ,May I Know How are you taking the name of the student,password in fronmt end. so that we can catch which student is being log in.???

Give Where Clause and Indicate the Student ID You want

SQL
SELECT sc.*,s.StudentId 
FROM TblStudent s
INNER JOIN TblStudentCourses sc ON s.StudentId=sc.StudentId 
WHERE s.StudentId=5
   
v3
Comments
Gihan Liyanage 1-Sep-14 6:59am
   
If you are using this inside the code then give the relevant id by using a variable
"...........
WHERE s.StudentId="+StudentIDVariable+";
Select A.Name,B.CourseName,B.Semester,B.CourseCode FROM TblStudent A
INNER JOIN TblStudentCourses B ON A.StudentId=B.StudentId
Where A.StudentId=1161213003
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900