397,549 views
21 votes
21 votes
what sql function will combine right and left join to return all matching records in both tables? 1 point inner join right join outer join left join

User Harry Lime
by
3.0k points

1 Answer

12 votes
12 votes
The SQL function that will combine RIGHT and LEFT JOIN to return all matching records in both tables is OUTER JOIN.

An OUTER JOIN combines the results of a LEFT JOIN and a RIGHT JOIN by returning all records from both tables, regardless of whether there is a matching record in the other table. This means that OUTER JOIN will return all records from the left table, even if there is no matching record in the right table. Similarly, it will return all records from the right table, even if there is no matching record in the left table. For records that have matching values in both tables, the resulting record will include all columns from both tables.

Here is an example of how you might use OUTER JOIN in a SQL query to combine the results of a LEFT JOIN and a RIGHT JOIN:

SELECT *
FROM table1
LEFT JOIN table2
ON table1.id = table2.id
UNION
SELECT *
FROM table1
RIGHT JOIN table2
ON table1.id = table2.id
This query will combine the results of the LEFT JOIN and RIGHT JOIN by using the UNION operator to combine the results of both JOIN clauses. The resulting records will include all matching records from both tables, as well as all records from table1 and table2 that do not have a matching record in the other table
User Jason Leveille
by
2.7k points