ASP组合查询

来源:百度知道 编辑:UC知道 时间:2024/09/20 20:28:31
目前我有4张表A,B,C,D
A:title time
B:title time
C:title
D:title Atime Btime
目的:要求将A B C3张表里所有的title字段进行对比,查找出所有不重复的记录,存到D表,并且将A与B表里不同记录的时间也写到D表里面去.
取3张表里不同的title字段已经会了,直接用sql="select title from A union select title from B union select title from C"
就可以了.问题在于怎么提取A里的time跟B里的time,分别提取出来插入到D的Atime跟Btime里???或者我这个思路是错误的.请高人指点

select a_1.title,b_1.title from A a_1,B b_1 where a_1.title not in (select a.title,b.title,c.title from A a,B b,C c where a.title=b.title and b.title=c.title) and b_1.title not in (select a.title,b.title,c.title from A a,B b,C c where a.title=b.title and b.title=c.title)

去掉三表里相同的记录

还要去掉每个表里相同的记录 我等下回来写

然后就可以插入到D表了

怎么不能修改啊!刚才吃饭去了!