Joined: 06 Dec 2004 Posts: 211 Location: Keane Inc., Minneapolis USA.
Joins are used to extract data from more than one table. We must use a Join condition while joining two tables. The Join condition depends on your business rules that apply on Tables. I will take a simple situation and explain you in detail.
Consider two tables EMP and DEPT with the following structure
EMP ( EMPNO,ENAME,JOB,SAL,DEPTNO) -- Employee details
DEPT(DEPTNO,DNAME,LOC) -- Department details
I need a query which extracts EMPNO,ENAME,JOB,SAL,DNAME and LOC means complete information of an EMPLOYEE. Some columns are from EMP and some are from DEPT. So we need to Join these 2 tables using a Join Condition. The Condition is DEPTNO of EMP is equal to DEPTNO of DEPT. The complete query is as follows..
SELECT EMPNO,ENAME,JOB,SAL,DNAME,LOC FROM EMP,DEPT where emp.DEPTNO=DEPT.DEPTNO;
while accessing DEPTNO we need to specify fully qualified name(Table.Column). Because it is common in both the tables.
emp.DEPTNO=DEPT.DEPTNO - Join Condition
But Its better to go through a material on Joins for full pledged knowledge.