选课表: course_id course_name std_id 学生信息表: std_id std_name .........select a.std_name,b.course_name from 学生信息表 a,选课表 b where b.course_id=1 and b.std_id=a.std_id;有错吗?我们以前学vf的时候就是这样写的,我和ATCG(ATCG) 同志的想法一致
"SELECT std_info.user_name,std_course.course_id,std_course.course_name FROM std_info,std_courseWHERE std_info.user_id=std_course.user_id AND std_course.course_id=1我写的语句就是这样的,和ATCG的有什么不同,高手指点。比如在course_table中有多个人选了course_id=1的课程,可是如果按照我写的语句就只能选出第一条数据。谢谢
where stu.id=sub.id
tble2表:ID,kecheng, ...select a.name, b.kecheng from table1 a,table2 b
where a.ID = b.ID;
table2表:学生ID,课程,……Select a.姓名, b.课程 from table1 a,table2 b
where a.学生ID = b.课程 (+)
course_id course_name std_id
学生信息表:
std_id std_name .........我现在要想得到选course_id=1的所有学生的姓名(即std_name)和与之对应的course_name,怎么做?谢谢
select a.std_name,b.course_name
from 学生信息表 a,选课表 b
where b.course_id=1 and b.std_id=a.std_id;
在学生信息表里 std_id 肯定是唯一的,
在选课表里面,同一个std_id可以有多个course_id
即:
std_id course_id
123 1
123 2
123 3因此 std_id和course_id相加是唯一的
std_id course_id std_name
1 1 heh
2 1 hello
3 1 kkdd
你怎么知道我说的不行啊,你试过我的SQL语句了吗???????????
我只是列举了一个学生的情况,所以只能查到一条记录.你的表里当然
不会只有一个学生了,因此你用我的SQL语句可以满足你的要求!!!!!! 我说你对数据库没有什么概念, 也不懂SQL.不过只要多实践,会长进很快的.
from 学生信息表 a,选课表 b
where b.course_id=1 and b.std_id=a.std_id;
学生信息表 选课表
std_id std_name std_id course_id course_name
1 猪八戒 1 1 数学
2 孙悟空 1 2 语文
3 沙和尚 1 3 英语
2 1 数学
2 2 语文
2 3 英语
3 1 数学
3 2 语文
3 3 英语
course_id course_name std_id
学生信息表:
std_id std_name .........select a.std_name,b.course_name
from 学生信息表 a,选课表 b
where b.course_id=1 and b.std_id=a.std_id;有错吗?我们以前学vf的时候就是这样写的,我和ATCG(ATCG) 同志的想法一致