sql 查询一个表的值,找到这个值在另外一个表中对于的数值

来源:百度知道 编辑:UC知道 时间:2024/06/06 16:51:42
有两个数据表:
第一个:25175_num_note
结构:
id exa_id class_id cou_id f_info
251 0 32, 33, 34 100||142
252 0 32, 33, 34 100||182
253 0 32, 33, 34 100||59
254 0 32, 33, 34 100||191
255 0 32, 33, 34
257 0 32, 33, 34 100||205
258 0 32, 33, 34 100||95
259 0 637||63
260 0 637||63
第二个表:25175_Exa
结构:
id Classes lj Remarks
32 1 2007
33 2 2007
34 3 2007
现在要通过查询第一个表中class_id中的编号对应在第二表中的ID(关联),现在要把把class_id所对应的班级(classes)全部显示出来,请问如何做?
asp文件中有这个查询的函数,但是就是得不到结果!
代码如下:
Sql_Lists="class_id"
Sql_tables="[25175_num_note]"
Sql_Conditions="id="&strid
sql=Sqlinfo(Sql_Lists,Sql_tables,Sql_Conditions,Sql_Sortings,Sql_Orders,Sql_Additional)
rs_grade_id = connopen(sql)
If IsArray(rs_grade_id)=True And rs_grade_id(0,0)<>"" Then
Sql_Lists="Classes"
Sql_tables=&qu

select * from 25175_num_note a,25175_Exa b
where a.class_id= b.id and a.class_id in('32','33','34')

select b.id,classes from 25175_num_note a,25175_Exa b
where a.class_id= b.id and a.class_id in('32','33','34')

无论你的数据如何动态只要你按照这种数据连接的方法都可以随时得到你想要的结果。
select DISTINCT a.class_id ,b.Classes lj ...这里写出你想要的任何一个表的列名,注意:a 表和 b 表的列需要加前辍 From 25175_num_note a inner join 25175_Exa b on a.class_id = b.class_id

如果需要条件可以在后面直接加
where a.class_id = '32' and b.Classes lj <> ""....