Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Inserting values from one table into another, with another set of values

How can I insert values from one table to another table, along with a set of other values? I have tables 'Employee' and 'Loan':

``` Employee Table Structure:
-------------------------
Employee No.
BasicPay

Loan Table Structure:
-------------------------
Employee No.
BasicPay
LoanAmount, and some other fields.
```
I want to insert EmployeeNo., BasicPay from 'Employee' table into 'Loan' table, and at the same time I want to insert a value for 'LoanAmount' column of 'Loans' table. How can I do this in a single query?

You need to at least know the "connecting" piece of information between the two tables in order to do this. It appears that in your example, the connecting column is the Employee No column. Therefore, in order to get the BasicPay value from the Employee table to populate the Loan table, you'd need to know the employee number when you are inserting into Loan.

```EMP Table
ENO   BASICPAY
---------- ----------
1      15000
2      20000
3      25000
```
To insert a row into the loan table for employee number 3 with a loan amount of 100,000:
```INSERT INTO loan
SELECT eno, basicpay, 100000
FROM emp
WHERE eno = 3 ;
```
Results in:
```LOAN Table
ENO   BASICPAY    LOANAMT
---------- ---------- ----------
3      25000     100000
```
You could also do this in a before INSERT trigger to populate the basicpay column with the appropriate value as follows:
```CREATE OR REPLACE TRIGGER i_loantab_trigger
BEFORE INSERT ON loan
FOR EACH ROW
DECLARE
v_basicpay	loan.basicpay%TYPE ;
BEGIN
SELECT basicpay
INTO v_basicpay
FROM employees
WHERE eno = :new.eno ;

:new.basicpay := v_basicpay ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
:new.basicpay := 0 ;
END ;
/
```
Then when you issue the following INSERT statement:
```INSERT INTO loan (eno, loanamt) VALUES (2, 150000) ;
```
You get:
```
LOAN Table
ENO   BASICPAY    LOANAMT
---------- ---------- ----------
2      20000     150000
```
Hope that helps!

## SearchDataManagement

• ### Pandemic triggered data security movement to DBaaS

Database-as-a-service technology has aided enterprises tasked with keeping data secure with IT professionals working from home ...

• ### Who belongs on a high-performance data governance team?

Putting together a high-quality data governance team can be a challenge. Explore the necessary team members and best practices ...

• ### Soda launches cloud service to improve data observability

Data quality vendor Soda has had a busy 2021, building out new services and raising funding to help organizations identify and ...

• ### Startup Veezoo emerges from stealth with NLQ-based platform

Aiming to be 'Siri for enterprises,' an analytics startup emerged from stealth with a platform that enables users to interact ...

• ### 15 data science tools to consider using in 2021

Numerous tools are available for data science applications. Read about 15, including their features, capabilities and uses, to ...

• ### Insightsoftware acquisition of Izenda targets embedded BI

ERP vendor Insightsoftware acquired embedded analytics specialist Izenda on April 15, marking its second purchase of an embedded ...

## SearchSAP

• ### S/4HANA Cloud SaaS ERP: Buying team overview

SAP's multi-tenant SaaS ERP, S/4HANA Cloud, is a viable choice for companies that need ease in their infrastructure management. ...

• ### SAP forms financial services partnership with Dediq

SAP and financial industry investment firm Dediq are forming a new business unit to develop applications that help banks and ...

• ### Unpatched applications threaten SAP security

Cyberattacks are a significant threat to unpatched, unprotected SAP applications, according to a new threat intelligence report ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Incorporate diversity and inclusion in technology design

DEI in technology is about more than creating a diverse workplace. We talked to a few DEI professionals about how teams build ...

• ### Microsoft previews OpenJDK distro to the delight of devs

In a move meant to attract more Java developers to its Azure cloud and further support the Java community, Microsoft launched a ...

• ### Supreme Court ruling on Java APIs eases developer worries

Now that the Supreme Court has ruled for Google over Oracle in their high-stakes copyright battle over Java APIs, developers can ...

## SearchDataCenter

• ### Programmable processor technology for next-gen data centers

The right processing technology can benefit your data center. Learn about advancements in CPU technologies, recent vendor ...

• ### Data processing units accelerate infrastructure performance

DPUs often run on networking packets to move information in the data center, instead of supporting processing workflows. Get an ...

• ### New Intel Ice Lake processors boost performance, security

Intel launches third-generation Xeon Scalable processors that bolster security, accelerate common data center workloads by 46% on...

## SearchContentManagement

• ### OpenText releases Cloud Editions content services updates

OpenText CE 21.2 includes federated document compliance that extends to Microsoft Office 365, along with a revamped content ...

As the pandemic disrupts paper workflows, Adobe courts small business users with simple webforms, digital signatures and payments...

• ### Know when to use a headless CMS and when it's not worth it

Headless CMSes aren't a silver bullet for every circumstance. Evaluate three solid use cases for a headless CMS and three ...

## SearchHRSoftware

• ### Face mask detection a newcomer to employee surveillance

Face mask detection has emerged as another form of employee surveillance technology, and its adoption may be helped indirectly by...

• ### 20 diversity and inclusion tools to power your DEI program

Diversity and inclusion tools shouldn't replace strategy, but these tools can help companies in multiple ways, from tracking ...

• ### DEI tools arrive at critical time for HR

Employers are being held accountable for meeting diversity, equity and inclusion goals, especially executives. HR vendors are ...

Close