A表
-------------------
wzid    ktid    ktname
---------------------
1      1       课题名
2      1       课题名
3      1       课题名
4      1       课题名
5      1       课题名
6      1       课题名
6      1       课题名
---------------------------------
B表
------------------------------
id     wzid    time
1        1        2010-08-12
2        2          2010-08-12
3        3         2010-08-12
--------------------------------
ktname
最后要查出的信息为
----------------------------
ktname       time
课题名        2010-08-12

解决方案 »

  1.   


    select distinct a.ktname,b.time
    from A表 a join B表 b on a.ktid=b.wzid
      

  2.   


    select ktname,time from A JOIN B ON A.wzid=B.wzid 
      

  3.   


    select A.ktname,B.time from A JOIN B ON A.wzid=B.wzid 
      

  4.   


    if OBJECT_ID ('A表') is not null
    drop table A表
    go
    create table A表(wzid int,ktid int,ktname varchar(6))
    insert into A表
    select 1, 1, '课题名' union all
    select 2, 1, '课题名' union all
    select 3, 1, '课题名' union all
    select 4, 1, '课题名' union all
    select 5, 1, '课题名' union all
    select 6, 1, '课题名' union all
    select 6, 1, '课题名'
    if OBJECT_ID ('B表') is not null
    drop table B表
    go
    create table B表(id int,wzid int,time date)
    insert into B表
    select 1, 1, '2010-08-12' union all
    select 2, 2, '2010-08-12' union all
    select 3, 3, '2010-08-12'
    select distinct a.ktname,b.time
    from A表 a join B表 b on a.ktid=b.wzidktname time
    课题名 2010-08-12
      

  5.   

    查的时候就是根据KTID等于几,查出KTID系列的数据,如ktid=2时会有跟他相关的数据出来。
      

  6.   


    select distinct a.ktname,b.time
    from A表 a join B表 b on a.wzid=b.wzidktname time
    课题名 2010-08-12
    改一下
      

  7.   

    你给的查询语句是全查出,我想知道如果根据ktid怎么查?就是ktid=2时查出相应的数据