Pergunta de entrevista da empresa Optimus

Explain different types of joins in sql?

Resposta da entrevista

Sigiloso

24 de set. de 2024

INNER JOIN: This join returns records that have matching values in both tables. If you're looking to fetch data present in both tables, this is the join you would use. SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID; LEFT (OUTER) JOIN: This join returns all records from the left table and the matched records from the right table. If there's no match, the result is NULL on the right side. SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name; RIGHT (OUTER) JOIN: It returns all records from the right table and the matched records from the left table. If there's no match, the result is NULL on the left side. SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name; FULL (OUTER) JOIN: This join combines the results of both left and right outer joins. It returns all records when there is a match in either left or right table. SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;