读书人

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

发布时间: 2012-01-07 21:41:55 作者: rapoo

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' 

读书人网 >J2EE开发

热点推荐