我的问题与数据库有关 [英] My Question is related to database
问题描述
我的数据库中有两个表,分别是TblStudent和TblStudentCourse。
(1) TblStudent 及其数据字段在下面
StudentId ........... ..........的请将.Name ............................... .... 密码
1161213003 .....................阿里........................................... 12
1161213004 ...................... Ahsan ....................... .................. 11
(2) TblStudentCourses 这是第二个表,其数据字段在下面
id ............ StudentId 。 ...........的 CourseName ...............的学期 ........ ............ CourseCode
1 ........,... 1161213003 .............数学.................................... ...... 1 ................................ 301
2。 ........... 1161213003 .............物理........................ ............. ..1 ................................ 302
在TblStudentCourse中,id是自动递增。
首先,学生创建他的帐户,他的帐户相关数据存储在 TblStudent ;然后他添加他的科目,科目相关数据存储在TblStudentCourse中。
我希望每个学生都能在gridview中看到他注册的课程详细信息,如课程名称,学期和课程代码。
我已经写了一个查询这个但是效果不好....
SELECT sc。*,s.StudentId FROM TblStudent s INNER JOIN TblStudentCourses sc ON s.StudentId = sc.StudentId;
问题是,当学生去看他注册的课程详细信息时,此查询显示其他学生的课程详细信息
给出条款并指明学生你想要的ID
SELECT sc。*,s.StudentId
FROM TblStudent s
INNER 加入 TblStudentCourses sc ON s.StudentId = sc.StudentId
WHERE s.StudentId = 5
INNER JOIN TblStudentCourses B ON A.StudentId = B.StudentId
Where A.StudentId = 1161213003
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
Give Where Clause and Indicate the Student ID You want
SELECT sc.*,s.StudentId FROM TblStudent s INNER JOIN TblStudentCourses sc ON s.StudentId=sc.StudentId WHERE s.StudentId=5
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
这篇关于我的问题与数据库有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!