如何在Oracle中从具有相同列名的两个表中检索数据

时间:2018-08-09 09:10:10

标签: sql oracle

我有两个表,一个工作表,另一个是备份表。两个表都有相同的列。现在,我希望在单个查询中来自两个表的几列数据。

可以在单个查询中吗?

表名:transationdetails工作表transationdetails_backup是备份表

例如,我在此处编写单个查询:

select txnid as txnid
     , date as transactiondate
     , amount as amount 
  from transationdetails;

select txnid as txnid
     , date as transactiondate
     , amount as amount 
  from transationdetails_backup;

预期结果:

select txnid as txnid
     , date as transactiondate
     , amount as amount 
  from transationdetails and transationdetails_backup;

3 个答案:

答案 0 :(得分:1)

尝试以下代码:

SELECT * FROM transationdetails 
UNION ALL
SELECT * FROM transationdetails_backup;

我相信简单的UNION ALL就能满足您的需求。

答案 1 :(得分:0)

您可以使用与MySQL中相同的Concat函数,最简单的方法就是放置

|| (“双管道”,您要加入的列之间)

EX :
select a.id , (a.id||a.name||b.job||a.stats) as backupDetail 
from "FirstTable" as a
inner join "SecondTable" as b on b.id = a.id 
Where a.id="YourParameter";

答案 2 :(得分:0)

这将起作用:

<script> function Click(element) { var jqueryVar= $(element).find("input[type='hidden'] [name='htmlfiled']").val(); $.ajax({ url : 'your.action', type : "post", data : { "bean name.field name" : jqueryVar }, success : function(res) { $("#datatableID").html(res); $('#complaintstatustable').DataTable({ "destroy":true, "pageLength":10 }); } }) } </script>