select * from a where column1 = condition1 union select * from b where column1 = condition1;
select XXXX,XXXX from 表A where .... union select XXXX,XXXX from 表B where ....
select cnt from ( select count(1) as cnt from a where condition...... union all select count(1) as cnt from b where condition...... and 0=(select nvl(count(1),0) from a where condition...... ) ) t where cnt=1;
说得不太明白,首先A,B两个表需要有关联字段,假设A,B 两个表通过字段ID 进行关联 那么select * from A a,B b where a.ID=b.ID and 某一条件
比如A seq A1,A2 101 a b 105 a c B seq B1,B2 103 b b 104 b c 查找seq为某一值的记录,A,B中有且只有一条记录 例如查找seq=103的 seq f1 f2 结果就是 103 b b
select seq,A1,A2 count(1) from (select seq ,A1,A2 from a where column1 union all select seq , B1,B2 from b where column1) group by seq,A1,A2 having count(1) = 1 ;
--首先A,B表结构的字段要一样 select * from (select seq,A1 f1,A2 f2 from A union all select seq,B1 f1,B2 f2 from B) t where seq=103
主的描述估计一般人理解不出来! select * from ((select * from a minus select * from b) union all (select * from b minus select * from a)) x where x.seq=??
不好意思。结果集还得有个字段 source,如果取自A,对应 是‘A’,如果取自B,则为‘B’ 比如A seq A1,A2 101 a b 105 a c B seq B1,B2 103 b b 104 b c 查找seq为某一值的记录,A,B中有且只有一条记录 例如查找seq=103的 seq f1 f2 source 结果就是 103 b b B 这些要用一句sql实现,怎么写啊。多谢
提问题尽量表达清楚,给出条件,然后想要的结果。 最好给一定数据更清楚。 select * from ( select seq, A1 f1, A2 f2, 'A' source from A union all select seq, B1 f1, B2 f2, 'B' source from B ) t where seq = 103
union
select * from b where column1 = condition1;
where ....
union
select XXXX,XXXX from 表B
where ....
select count(1) as cnt from a
where condition......
union all
select count(1) as cnt from b
where condition......
and 0=(select nvl(count(1),0) from a
where condition...... )
) t
where cnt=1;
那么select * from A a,B b where a.ID=b.ID and 某一条件
seq A1,A2
101 a b
105 a c
B
seq B1,B2
103 b b
104 b c
查找seq为某一值的记录,A,B中有且只有一条记录 例如查找seq=103的
seq f1 f2
结果就是 103 b b
(select seq ,A1,A2 from a where column1
union all
select seq , B1,B2 from b where column1)
group by seq,A1,A2 having count(1) = 1 ;
--首先A,B表结构的字段要一样
select *
from
(select seq,A1 f1,A2 f2 from A
union all
select seq,B1 f1,B2 f2 from B) t
where seq=103
select * from
((select * from a
minus
select * from b)
union all
(select * from b
minus
select * from a)) x
where x.seq=??
比如A
seq A1,A2
101 a b
105 a c
B
seq B1,B2
103 b b
104 b c
查找seq为某一值的记录,A,B中有且只有一条记录 例如查找seq=103的
seq f1 f2 source
结果就是 103 b b B
这些要用一句sql实现,怎么写啊。多谢
select *
from (
select seq, A1 f1, A2 f2, 'A' source from A
union all
select seq, B1 f1, B2 f2, 'B' source from B
) t
where seq = 103