第一张表3个字段:A1,B1,C1 第二张表3个字段:A2,B2,C2
搜索这6个字段出来 A1,B1,C1,A2,B2,C2 放进Dataset当中
我需要的结果是 当 任意2张表的字段值不同就空行
数据例子是这样的:
A1 B1 C1 A2 B2 C2 1 1 1 1 1 1 1 1 2 1 1 2 1 1 3 空 空 空 1 2 1 1 2 1 空 空 空 1 2 2 空 空 空 1 2 3 2 1 1 2 1 1 2 1 2 空 空 空
搜索出来有6列,前3列来自一张表,后三列来自一张表 前三列的在后三列中没有,则 空行 后三列在前三列中没有,则空行
这就是数据例子 不知道大家看懂了没有 请问SQL文我该怎么写
不好意思 小弟分不多了
create table t1(A1 int ,B1 int,C1 int) insert into t1(A1,B1,C1) select 1,2,1 union select 1,1,1 union select 2,1,1
create table t2(A2 int ,B2 int,C2 int) insert into t2(A2,B2,C2) select 1,2,1 union select 1,2,2 union select 2,2,1
select A1,B1,C1,A2,B2,C2 FROM t1 FULL JOIN t2 ON t1.A1 = t2.A2 AND t1.B1 = t2.B2 AND t1.C1 = t2.C2
drop table t1 drop table t2
是不是这个意思?
select * from t1 full join t2 on t1.a1=t2.a2 and t1.b1=t2.b2 and t1.c1=t2.c2
感谢ping3000(苦练葵花点穴手) A1 B1 C1 A2 B2 C2 1 1 1 1 1 1 1 1 2 1 1 2 1 1 3 空 空 空 1 2 1 1 2 1 空 空 空 1 2 2 空 空 空 1 2 3 2 1 1 2 1 1 2 1 2 空 空 空
这个检索的意思却是有点复杂!
说白了 A1 B1 C1所有不为空的行数就是A1 B1 C1 所在表的数据总行 A2 B2 C2所有不为空的行数就是A2 B2 C2 所在表的数据总行 检索出来的数据只是并排的按序排列 两个都有的现实,没有的空行!
|