有两个表都有name这个字段,值是不一样的,能一句SQL查询出来吗select name from table1 where orderID = '123'
select name from table2 where  age = '35'
这两条语句能合成一条吗?如果能合并,怎么在rs里面分辨哪个是表1的结果哪个是表2的结果

解决方案 »

  1.   

    select t.name, o.name from table1 as t, table2 as o where t.orderID='123' and o.age=35;你试试。
      

  2.   

    select tb1.name as tb1_name,tb2.name as tb2_name
    from (select name from table1 where orderID = '123') tb1,
    (select name from table2 where  age = '35') tb2因为没有链接关系,你要保证2个子查询的结果唯一
      

  3.   

    SELECT name, 'table1' AS category FROM table1 WHERE ...
    UNION ALL
    SELECT name, 'table2' AS category FROM table2 WHERE ...
      

  4.   

    怎么从RS取出两个name值呢?
      

  5.   

    在sqlserver里面查询没问题,JAVA里面报异常name列无效,为什么呀
      

  6.   

    改成
    SQL codeselect t.name, o.name from table1 t as tname, table2 o as oname where t.orderID='123' and o.age=35;
      

  7.   


    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的时候是第二个查询的结果