SQL Aliases for QQuery

Up until now, we've only described doing simple joins with QQuery, where each table is only needed for a single related record. But what about when you need to check on multiple entries in the same joined table. In standard SQL, you would join the table a second time, giving it a new name. And that's exactly how you do it in QQuery as well, using QQ::alias().

In the example 1 below, we need to find who belongs to both the ACME Website Redesign and the State College HR System projects. We do this simply by joining the membership association table twice, each time with a different alias. This allows us to create a condition that says that one associated project has an ID of 1, while a different associated project also has an ID of 2.

In a slightly more complex example 2 below, we are looking for all projects that are associated with two other projects (each is specified by name). We use the same technique with QQ::alias() as in example 1, except that we now mix it in with relationships expanded to other tables.

Example 1: Project members whose are in both project 1 and 2

Kendall Public
Alex Smith
Karen Wolfe

Example 2: Projects that are related to both 'Blueman Industrial Site Architecture' and 'ACME Payment System' projects

ACME Website Redesign (The redesign of the main website for ACME Incorporated)

Example 3: Managers having one least a project with a conson milestone, and for each manager, the first voyel milestone and the first conson one

John Doeooo (, Milestone F)
Mike Ho (Milestone E, Milestone D)
Karen Wolfe (Milestone A, Milestone B)

Example 4: Projects with, for each one, the "min" city from the addresses containing 'r' and the "min" city from the addresses NOT containing 'r'

ACME Website Redesign (Dallas, Palo Alto)
State College HR Systzzzz (Dallas, Palo Alto)
Blueman Industrial Site Architecture (Phoenix, )
ACME Payment System (Dallas, New York)
PROFILING INFORMATION FOR DATABASE CONNECTION #1: 5 queries performed. Please click here to view profiling detail