Please note that the following blog post provides a summary view for what you need to get done (left column) and quick examples that illustrate how to do it in SQL (right column with SQL code in red). For more information please see the resources below:
- SQL Course 2. (2018). SQL Course 2: Interactive Online SQL Training. Retrieved from http://www.sqlcourse2.com/
- Mode Community. (2018). The SQL Tutorial for Data Analysis. Retrieved from https://community.modeanalytics.com/sql/tutorial/introduction-to-sql/
- Programmer Interview. (2018). Practice SQL Interview Questions and Answers. Retrieved from http://www.programmerinterview.com/index.php/database-sql/practice-interview-question-1/
Equijoins |
SELECT e.ename, e.deptno, d.deptno, d.name FROM emp e INNER JOIN dept d ON e.deptno = d.deptno |
Non-Equijoins |
SELECT e.ename, e.sal, s.grade FROM emp e INNER JOIN salgrade s WHERE e.sal BETWEEN s.losal AND s.hisal From: grade losal hisal ----- ----- ------ 1 700 1200 2 1201 1400 3 1401 2000 4 2001 3000 5 3001 9999 Gives the following solution: ename sal grade ---------- --------- --------- JAMES 950 1 SMITH 800 1 ADAMS 1100 1 |
Outer joins |
SELECT e.ename, e.deptno, d.deptno FROM emp e RIGHT JOIN dept d ON e.deptno = d.deptno SELECT e.deptno, d.deptno, d.name FROM emp e LEFT JOIN dept d ON e.deptno = d.deptno |
Self Joins |
SELECT worker.ename +’ works for’+ manager.ename FROM emp worker, emp manger ON worker.mgr = manager.empno |