0% found this document useful (0 votes)
4 views2 pages

PR 16

Uploaded by

beladarsonal
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)
4 views2 pages

PR 16

Uploaded by

beladarsonal
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
You are on page 1/ 2

CREATE TABLE DEPT (

dept_no INT PRIMARY KEY,

dept_name VARCHAR(50),

location VARCHAR(50)

);

INSERT INTO DEPT VALUES (10, 'Sales', 'Mumbai');

INSERT INTO DEPT VALUES (20, 'HR', 'Pune');

INSERT INTO DEPT VALUES (30, 'IT', 'Nashik');

CREATE TABLE EMP (

emp_no INT PRIMARY KEY,

emp_name VARCHAR(50),

dept_no INT,

salary DECIMAL(10, 2),

manager_id INT,

FOREIGN KEY (dept_no) REFERENCES DEPT(dept_no),

FOREIGN KEY (manager_id) REFERENCES EMP(emp_no)

);

INSERT INTO EMP VALUES (103, 'Sumit Patil', 10, 80000, NULL);

INSERT INTO EMP VALUES (105, 'Ravi', 20, 70000, NULL);

INSERT INTO EMP VALUES (101, 'Nikhil', 10, 50000, 103);

INSERT INTO EMP VALUES (102, 'Amit', 10, 45000, 103);

INSERT INTO EMP VALUES (104, 'Sneha', 20, 40000, 105);

SELECT e.emp_no, e.emp_name, e.dept_no, d.location

FROM EMP e

JOIN DEPT d ON e.dept_no = d.dept_no


WHERE e.emp_name = 'Nikhil';

SELECT e.emp_no, e.emp_name, d.dept_name

FROM EMP e

JOIN DEPT d ON e.dept_no = d.dept_no

WHERE d.dept_name = 'Sales';

SELECT e.emp_no, e.emp_name, d.dept_name

FROM EMP e

JOIN DEPT d ON e.dept_no = d.dept_no

WHERE d.dept_name <> 'Sales';

SELECT e.emp_name, e.salary

FROM EMP e

JOIN EMP m ON e.manager_id = m.emp_no

WHERE m.emp_name = 'Sumit Patil';

You might also like