Skip to main content

Posts

Showing posts with the label sql

What is the difference between a join and a union operation in SQL? Provide an example of when you would use each operation.

  In SQL, a JOIN operation and a UNION operation are two different operations used to combine data from two or more tables. The main differences between these two operations are: JOIN operation: Joins combine rows from two or more tables based on a related column between them. The result of a join operation is a new table that contains columns from both tables. Example: Suppose you have two tables, "Employees" and "Departments," with a common column "DepartmentID." You can join these two tables using the "INNER JOIN" clause as follows: sql SELECT Employees.Name, Departments.DepartmentName FROM Employees INNER JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID; This query will combine the "Name" column from the "Employees" table with the "DepartmentName" column from the "Departments" table based on the common "DepartmentID" column. UNION operation: Unions combine rows from ...