0% found this document useful (0 votes)
2 views1 page

program 5

The document outlines the creation of a table named 'employees1' with columns for employee ID, name, salary, and department ID, including a foreign key constraint. It also includes SQL commands to insert five employee records into the table. Finally, a nested query is provided to select employee names based on department locations in New York.

Uploaded by

souravvishali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

program 5

The document outlines the creation of a table named 'employees1' with columns for employee ID, name, salary, and department ID, including a foreign key constraint. It also includes SQL commands to insert five employee records into the table. Finally, a nested query is provided to select employee names based on department locations in New York.

Uploaded by

souravvishali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Create table

CREATE TABLE employees1 (

emp_id INT PRIMARY KEY,

name VARCHAR(50),

salary DECIMAL(10,2),

dept_id INT,

FOREIGN KEY (dept_id) REFERENCES departments(dept_id)

);

Insert values

INSERT INTO employees1 (emp_id, name, salary, dept_id) VALUES

(1, 'Alice', 50000, 101),

(2, 'Bob', 60000, 102),

(3, 'Charlie', 55000, 101),

(4, 'David', 70000, 103),

(5, 'Eve', 65000, 102);

Nested Query

SELECT name

FROM employees1

WHERE dept_id IN (SELECT dept_id FROM departments WHERE location = 'New York');

You might also like