表a: 表b:
id name id name
1 aaa 1 bbb
1 bbb 1 ccc
我想取初表a和表b中name字段的合并结果
可以用循环
rs.getString("name");
来获得结果:
aaa
bbb
ccc
11 个解决方案
#1
select name from a
union
select name from b
union
select name from b
#2
select name from a
union
select name from b
union
select name from b
#3
各位老兄:其实这两个表要经过全连接:看看这个sql如何改,可以合并:a.poID ,b.poID 为一个字段?
select Distinct a.poID ,b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
select Distinct a.poID ,b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
#4
mark
#5
我这样干了,也行,但是太死板了。
(select Distinct a.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
union
(select Distinct b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
(select Distinct a.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
union
(select Distinct b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
#6
select distinct name from a
union
select distinctname from b
union
select distinctname from b
#7
select distinct name from a
union
select distinct name from b
union
select distinct name from b
#8
select distinct name from a
union
select distinct name from b
---------
感觉没有必要用distinct
union all 时用distinct,如果是union就会自动去除重复值。
明白楼主的意思,
from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
这段话比较浪费的意思,能不能合并处理。
---
如果就是这样合并两个字段这样就可以了,如果是还有c.poID等其他字段,那就可以写个函数之类的,用动态sql执行就可以。
union
select distinct name from b
---------
感觉没有必要用distinct
union all 时用distinct,如果是union就会自动去除重复值。
明白楼主的意思,
from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
这段话比较浪费的意思,能不能合并处理。
---
如果就是这样合并两个字段这样就可以了,如果是还有c.poID等其他字段,那就可以写个函数之类的,用动态sql执行就可以。
#9
太郁闷了。在查询分析器里可以运行,用java 语句执行,
竟然说:!!!!!!!!!!!!!!!!!!!
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: 'a' 附近有语法错误。
受不了了,这样郁闷的问题都又,看来是jdbc的功能不支持吗?谁遇到过这中问题!!!???
竟然说:!!!!!!!!!!!!!!!!!!!
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: 'a' 附近有语法错误。
受不了了,这样郁闷的问题都又,看来是jdbc的功能不支持吗?谁遇到过这中问题!!!???
#10
改成视图:
create view xx
as
select distinct name from a
union
select distinct name from b
go
create view xx
as
select distinct name from a
union
select distinct name from b
go
#11
修修补补总算通过了。结果对不对,鬼才知道。反正客户也不知道。让他用去吧。哈哈
#1
select name from a
union
select name from b
union
select name from b
#2
select name from a
union
select name from b
union
select name from b
#3
各位老兄:其实这两个表要经过全连接:看看这个sql如何改,可以合并:a.poID ,b.poID 为一个字段?
select Distinct a.poID ,b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
select Distinct a.poID ,b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
#4
mark
#5
我这样干了,也行,但是太死板了。
(select Distinct a.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
union
(select Distinct b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
(select Distinct a.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
union
(select Distinct b.poID from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07')
#6
select distinct name from a
union
select distinctname from b
union
select distinctname from b
#7
select distinct name from a
union
select distinct name from b
union
select distinct name from b
#8
select distinct name from a
union
select distinct name from b
---------
感觉没有必要用distinct
union all 时用distinct,如果是union就会自动去除重复值。
明白楼主的意思,
from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
这段话比较浪费的意思,能不能合并处理。
---
如果就是这样合并两个字段这样就可以了,如果是还有c.poID等其他字段,那就可以写个函数之类的,用动态sql执行就可以。
union
select distinct name from b
---------
感觉没有必要用distinct
union all 时用distinct,如果是union就会自动去除重复值。
明白楼主的意思,
from TS_CX_HJ a FULL OUTER JOIN tt_jkrecord b on a.poJID=b.poJID and a.chDay=b.stDay
where a.poJID='3' and DATEPART(yyyy,a.chDay)='2003' and DATEPART(mm,a.chDay)='7' and DATEPART(dd,a.chDay)='07'
这段话比较浪费的意思,能不能合并处理。
---
如果就是这样合并两个字段这样就可以了,如果是还有c.poID等其他字段,那就可以写个函数之类的,用动态sql执行就可以。
#9
太郁闷了。在查询分析器里可以运行,用java 语句执行,
竟然说:!!!!!!!!!!!!!!!!!!!
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: 'a' 附近有语法错误。
受不了了,这样郁闷的问题都又,看来是jdbc的功能不支持吗?谁遇到过这中问题!!!???
竟然说:!!!!!!!!!!!!!!!!!!!
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 1 行: 'a' 附近有语法错误。
受不了了,这样郁闷的问题都又,看来是jdbc的功能不支持吗?谁遇到过这中问题!!!???
#10
改成视图:
create view xx
as
select distinct name from a
union
select distinct name from b
go
create view xx
as
select distinct name from a
union
select distinct name from b
go
#11
修修补补总算通过了。结果对不对,鬼才知道。反正客户也不知道。让他用去吧。哈哈