从多个表中获取数据

时间:2015-11-22 19:12:40

标签: sql oracle

我的表1有列

  • ConcurrentLinkedDeque<SoftReference<T>> deque; void push(T value) { deque.push(new SoftReference<T>(value)); } T tryPop() { while (true) { SoftReference<T> ref = deque.pollLast(); if (ref == null) { return null; } T value = ref.get(); if (value != null) { return value; } } }
  • userid
  • deptname
  • deptid
  • working_in
  • joining_date

表2有列

  • profession
  • userid
  • salary
  • doj

表3包含

  • user_mail
  • userid
  • deptname
  • deptid

表1和表2都包含一些行。表3不包含任何行。

表3的值将是表1和表2中值的组合。

如何仅通过提取表1和表2中所需的详细信息salaryuseriddeptnamedeptid来更新表3?

2 个答案:

答案 0 :(得分:0)

  var requestError = function() {
    // The response is always empty
    // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
    completeRequest(callback, -1, null, null, '');
  };

通过这种方式,您可以在单个查询中获取两个表中的详细信息。请注意,我根据“userid”列使用了连接。这样“薪水”将是同一个用户(假设“userid”是共享PK)。

修改 在上面的示例代码中,您不插入任何内容。只有一个SELECT语句。这意味着,您只从table1和table2中提取相关数据。为了将数据放入table3中,您需要一个INSERT stetment。你可以在这里查看http://www.techonthenet.com/oracle/insert.php,结果应该是:

select t1.userid, t1.deptname, t1.deptid, t2.salary from table1 t1
join table2 t2
on t1.userid=t2.userid

答案 1 :(得分:0)

假设

  1. 您的“表1”名为table_1
  2. 您的“表2”名为table_2
  3. 您的“表3”名为table_3
  4. 您的“值组合”是userid列上表1和表2之间的联接,
  5. 您的“我更新表3”表示您希望将“值组合”存储到表3中,
  6. 然后你的查询将是:

    insert into table_3 (userid, deptname, deptid, salary)
    select userid, T1.deptname, T1.deptid, T2.salary
    from table_1 T1
        join table_2 T2 using (userid)
    ;