Creating Table Joins

Many times, the data that you want to retrieve is maintained in multiple tables.

For example, in the database that you're working with:

To compare and retrieve data from more than one table during a query, use the WHERE clause to join two tables through common information.

Usage example

For example, to return employee names, start dates, department names, and salaries for employees that work for the HR department, you would build a query that looks like this:

<CFQUERY NAME="GetEmployees" DATASOURCE="HRApp"> 
    SELECT Departments.Department.Name, 
    Employees.FirstName,
    Employees.LastName,
    Employees.StartDate,
    Employees.Salary
    FROM Departments, Employees
    WHERE Departments.Department_ID = Employees.Department_ID
    AND Departments.Department_Name = 'HR'
</CFQUERY>