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
-------------------
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
select distinct a.ktname,b.time
from A表 a join B表 b on a.ktid=b.wzid
select ktname,time from A JOIN B ON A.wzid=B.wzid
select A.ktname,B.time from A JOIN B ON A.wzid=B.wzid
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
select distinct a.ktname,b.time
from A表 a join B表 b on a.wzid=b.wzidktname time
课题名 2010-08-12
改一下