Here are the examples of Oracle SQL queries to join two tables.
Using INNER JOIN to Join Two Tables in Oracle
The following SQL query will join the emp
and emp_docs
table using the INNER JOIN
clause:
select e.first_name, e.last_name, d.doc_title from emp e inner join emp_docs d on e.emp_id = d.emp_id where e.deptno = 10;
Below is another SQL query example without the INNER JOIN clause:
select e.first_name, e.last_name, d.doc_title from emp e, emp_docs d where e.emp_id = d.emp_id;
The above SQL queries will return the data for those employees who exist in both tables. If you want to get all the data from the emp
table, even if the emp_docs
table has no data for all the employees, use the LEFT OUTER JOIN clause. Below is an example:
select e.first_name, e.last_name, d.doc_title from emp e left outer join emp_docs d on e.emp_id = d.emp_id where e.deptno = 10;
To learn more about the joins, check the following Oracle tutorial.
Leave a comment
You must login or register to add a new comment.