有两个表都有name这个字段,值是不一样的,能一句SQL查询出来吗select name from table1 where orderID = '123'
select name from table2 where age = '35'
这两条语句能合成一条吗?如果能合并,怎么在rs里面分辨哪个是表1的结果哪个是表2的结果
select name from table2 where age = '35'
这两条语句能合成一条吗?如果能合并,怎么在rs里面分辨哪个是表1的结果哪个是表2的结果
from (select name from table1 where orderID = '123') tb1,
(select name from table2 where age = '35') tb2因为没有链接关系,你要保证2个子查询的结果唯一
UNION ALL
SELECT name, 'table2' AS category FROM table2 WHERE ...
SQL codeselect t.name, o.name from table1 t as tname, table2 o as oname where t.orderID='123' and o.age=35;
select name,'表1' as tempColumn from table1 where orderID = '123'
union all
select age,'表2' as tempColumn from table2 where age = '35'用resultSet.getString(tempColumn);判断,当 值等于 表1 的时候,即为第一个查询的结果,为表2的时候是第二个查询的结果