SQL Assignment 8

##mssqlserver ##sql

Chander Shekhar Jul 21 2021 · 1 min read
Share this

Task 1. Write an SQL query to fetch intersecting records of two tables.

Solution : SELECT Worker_Id, First_Name, Last_Name, Salary FROM WORKER  INTERSECT SELECT Worker_Id, First_Name, Last_Name, Salary FROM WORKER_COPY

Task 2. Write an SQL query to show records from one table that another table does not have.

Solution : THERE ARE TWO WAYS BOTH HAVE SAME RESULT

1. 

SELECT * FROM WORKER WHERE Worker_Id NOT IN

(

SELECT Worker_Id FROM WORKER_COPY

)

USING NOT IN OPERATOR

2.

SELECT * FROM WORKER AS A WHERE NOT EXISTS

(

SELECT * FROM WORKER_COPY AS B

WHERE A.Worker_Id =B.Worker_Id

)

USING NOT EXISTS OPERATOR
Comments
Read next