The $query object
Last modified: November 25, 2006 - 23:23
function _views_query($views_get_title_table = 'node', $views_get_title_field = 'nid',
function add_field($field, $table = '$$', $alias = '') {
function set_distinct() {
function clear_fields() {
function set_count_field($field) {
function add_where($clause) {
function add_orderby($table, $field, $order, $alias = '') {
function add_groupby($clause) {
function ensure_table($table) {
function add_table($table, $ensure_path = false, $howmany = 1, $joininfo = NULL) {
function queue_table($table) {
function set_header($header) {
function ensure_path($table, $traced = array(), $add = array()) {
function get_table_name($table, $table_num, $alias_prefix = '') {
function query($getcount = false) {

Take a look at
Take a look at views_query.inc for thorough documentation of the query object and how it works.
ensure_table - join order
The order in which you add tables is important. Tables are joined using the order of the tables as they are defined. If a field requires a join that is not immediately part of a view, you will need to add the "ensure_table" before you add a new join.