首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

java这样的查询语句能写吗?解决办法

2012-01-07 
java这样的查询语句能写吗?有两个表都有name这个字段,值是不一样的,能一句SQL查询出来吗Java codeselect n

java这样的查询语句能写吗?
有两个表都有name这个字段,值是不一样的,能一句SQL查询出来吗

Java code
select name from table1 where orderID = '123'select name from table2 where  age = '35'这两条语句能合成一条吗?如果能合并,怎么在rs里面分辨哪个是表1的结果哪个是表2的结果


[解决办法]
SQL code
SELECT name, 'table1' AS category FROM table1 WHERE ...UNION ALLSELECT name, 'table2' AS category FROM table2 WHERE ...
[解决办法]
SQL code
select name,'表1' as tempColumn from table1 where orderID = '123'union allselect age,'表2' as tempColumn from table2 where age = '35' 

热点排行
Bad Request.