Hi Nola,
Just show your boss the technical difference between using different types of JOINS. The results will be different!
(I'm using Oracle, so the syntax may be a touch different, sorry.)
SQL> CREATE TABLE DEPT
2 (DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,
3 DNAME VARCHAR2(14) ,
4 LOC VARCHAR2(13) ) ;
Table created.
SQL> CREATE TABLE EMP
2 (EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,
3 ENAME VARCHAR2(10),
4 JOB VARCHAR2(9),
5 MGR NUMBER(4),
6 HIREDATE DATE,
7 SAL NUMBER(7,2),
8 COMM NUMBER(7,2),
9 DEPTNO NUMBER(2) );
Table created.
SQL> INSERT INTO DEPT VALUES (10,'ACCOUNTING','NEW YORK');
SQL> INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');
SQL> INSERT INTO DEPT VALUES (30,'SALES','CHICAGO');
SQL> INSERT INTO EMP VALUES
2 (7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
SQL> INSERT INTO EMP VALUES
2 (7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
SQL> INSERT INTO EMP VALUES
2 (7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
SQL> INSERT INTO EMP VALUES
2 (7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,40);
SQL> INSERT INTO EMP VALUES
2 (7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,40);
SQL> INSERT INTO EMP VALUES
2 (7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,40);
This is the way you do your queries (and I do mine, generally ;-):
SQL> select emp.empno, emp.ename, dept.dname
2 from emp, dept
3 where emp.deptno = dept.deptno;
EMPNO ENAME DNAME
7839 KING ACCOUNTING
7566 JONES RESEARCH
7369 SMITH RESEARCH
...which is the same as an INNER JOIN:
SQL> select emp.empno, emp.ename, dept.dname
2 from emp inner join dept
3 on emp.deptno = dept.deptno;
EMPNO ENAME DNAME
7839 KING ACCOUNTING
7566 JONES RESEARCH
7369 SMITH RESEARCH
What your boss is asking for is a LEFT JOIN, which says "if there are any rows in
the table on the right that don't match the rows on the left, MAKE UP a null row
so the table on the left will still get included in the query results" (notice there
are three more rows in the results, those members with deptno=40. There IS NO
deptno=40 in DEPT):
SQL> select emp.empno, emp.ename, dept.dname
2 from emp left outer join dept
3 on emp.deptno = dept.deptno;
EMPNO ENAME DNAME
7839 KING ACCOUNTING
7369 SMITH RESEARCH
7566 JONES RESEARCH
7654 MARTIN
7521 WARD
7499 ALLEN
6 rows selected.
A RIGHT JOIN is the same as the LEFT, except it makes up null rows for the table on
the left so rows on the right are guaranteed to be included in the query results.
SQL> select emp.empno, emp.ename, dept.dname
2 from emp right outer join dept
3 on emp.deptno = dept.deptno;
EMPNO ENAME DNAME
7839 KING ACCOUNTING
7566 JONES RESEARCH
7369 SMITH RESEARCH
SALES
4 rows selected.
One more is a FULL JOIN... which makes up rows in both tables, but this one is a
performance hog, as it basically does a UNION ALL on a RIGHT JOIN and a LEFT JOIN:
SQL> select emp.empno, emp.ename, dept.dname
2 from emp full outer join dept
3 on emp.deptno = dept.deptno;
EMPNO ENAME DNAME
7839 KING ACCOUNTING
7369 SMITH RESEARCH
7566 JONES RESEARCH
7654 MARTIN
7521 WARD
7499 ALLEN
SALES
7 rows selected.
Hope that helps!
smd